添加动态评级控件时出现奇怪的编译问题
我正在使用 ajax 控件包动态地将评级控件添加到预定义表的特定列,该控件的最大评级取决于其前面的列。
无论如何,当使用动态控件时,我了解到您应该在每次页面加载时重新添加它们,因此我添加了一个 Session 变量,它可以让我 - 当页面不是第一次加载时并且这个布尔值为 true - 添加这些评级控件及其由此页面上的事件处理程序处理的事件(更改)。
这些是处理评级事件的 2 个代码块 &&动态添加到表中的列:
事件
protected void Page_Load(对象发送者, EventArgs e) { if (!Page.IsPostBack) { ScriptManager1.RegisterAsyncPostBackControl(imbGebruikers); ScriptManager1.RegisterAsyncPostBackControl(imbModellen); imbvolgende.Enabled = true; ddlGebruikers.Items.Add(new ListItem("", "")); 字符串 ingelogdegebruikerid = (String)Session["gebruikerid"]; lbl1.Text = "评估者:" + Database.geefGebruikerNaam(ingelogdegebruikerid); IEnumerator
evaluatieformulieren = Database.laadFormulierenIn().GetEnumerator(); 列表 mijnformulieren = new List (); 会话[“mijnformulieren”] = mijnformulieren; while (evaluatieformulieren.MoveNext()) { if (((evaluatieformulieren.Current.GebruikerevaluatorID.ToString() == ingelogdegebruikerid) && (evaluatieformulieren.Current.Afgewerkt == "nee"))) mijnformulieren.Add(evaluatieformulieren.Current); } IEnumerator mijnenumerator = mijnformulieren.GetEnumerator(); while (mijnenumerator.MoveNext()) { String geevalueerdenaam = Database.geefGebruikerNaam(mijnenumerator.Current.GebruikergeevalueerdID); 布尔 ziteralin = false; foreach(ddlGebruikers.Items 中的 ListItem 项) { if (item.Text == geevalueerdenaam) 齐特灵=真; } if (!ziteralin) ddlGebruikers.Items.Add(new ListItem(geevalueerdenaam, mijnenumerator.Current.GebruikergeevalueerdID)); } imbFormulier.Visible = false; 会话["formulieractief"] = false; } 别的 { //如果页面不是第一次加载,则将评级控件重新添加到我的表中&&这个布尔值是 true(表格正在显示) 布尔formulieractief = (Boolean)Session["formulieractief"]; if(公式活动) { Evaluatieform mijnform = (Evaluatieform)Session["formulier"]; 列表<域标准> domeincontrolenum = mijnform.controls; AjaxControlToolkit.Rating dynamischeratingcontrol = new AjaxControlToolkit.Rating(); dynamischeratingcontrol.FilledStarCssClass = "filledRatingStar"; dynamischeratingcontrol.EmptyStarCssClass = "emptyRatingStar"; foreach(DomeinsCriteriums domeincontrol in domeincontrolenum) { foreach(CriteriumLijn criteriumcontrol in domeincontrol.Criterias) { ScriptManager1.RegisterAsyncPostBackControl(dynamischeratingcontrol); dynamischeratingcontrol.ID = criteriumcontrol.Criterium.CriteriumNaam; dynamischeratingcontrol.MaxRating = Convert.ToInt32(criteriumcontrol.Criterium.Domein.DomeinGewicht); Criteriumcontrol.Rating = dynamischeratingcontrol; criteriumcontrol.Rating.Changed += new AjaxControlToolkit.RatingEventHandler( rating_Changed); } } } } }
处理每个评级控件的每个事件的事件处理程序
//每个控件的事件处理程序 protected void rating_Changed(对象发送者,AjaxControlToolkit.RatingEventArgs e) { AjaxControlToolkit.Rating gefirederatingcontrol = (AjaxControlToolkit.Rating) 发送者; 字符串 ratingid = gefirederatingcontrol.ID;
Evaluatieform mijnform = (Evaluatieform) Session["formulier"]; IEnumerator<领域标准> domeincontrolenum = mijnform.controls.GetEnumerator(); while (domeincontrolenum.MoveNext()) { foreach(CriteriumLijn criteriumcontrol in domeincontrolenum.Current.Criterias) { if (criteriumcontrol.Criterium.CriteriumNaam == ratingid) Criteriumcontrol.Score = gefirederatingcontrol.CurrentRating; } } 会话["formulier"] = mijnform;
}
加载页面时的错误
无论如何,我在 Visual Studio 中没有收到任何错误,但是当我启动我的网站并导航到该页面时,即使他不能甚至在页面打开时执行代码(要添加评级控件的表不可见,因此让我在每个页面加载时读取控件的布尔值是 false),他给了我这些编译错误:
- 编译错误
说明:编译过程中发生错误。服务此请求所需的资源。请查看以下具体错误详细信息并适当修改您的源代码。
Compiler Error Message: CS0029: Cannot implicitly convert type
'System.Collections.Generic.List<DomeinsCriteriums>.Enumerator' to
'System.Collections.Generic.IEnumerator<DomeinsCriteriums>'
源错误:
Line 334:
Line 335: Evaluatieform mijnform = (Evaluatieform) Session["formulier"];
Line 336: IEnumerator<DomeinsCriteriums> domeincontrolenum = mijnform.controls.GetEnumerator();
Line 337:
Line 338: while (domeincontrolenum.MoveNext())
Source File: e:\Website Werkend (07-04-11)\Evaluatie.aspx.cs Line: 336
如果我不注释第 58 行,我会得到相同的错误。
有人对此有任何想法吗?我一无所知。
I am using the ajax controlkit to dynamicly add ratingcontrols to a certain column of a predefined table, with the maxrating of that control depending on column before him.
Anyways, when using dynamic controls, I have learned that you should re-add them every time on a page load, so I added a Session variable that lets me - when the page is not being loaded for the first time AND this boolean is true - add these rating controls with their event(Changed) handled by an eventhandler on this page.
These are the 2 blocks of code that handle the rating events && the dynamic adding to the column in a table:
Event
protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { ScriptManager1.RegisterAsyncPostBackControl(imbGebruikers); ScriptManager1.RegisterAsyncPostBackControl(imbModellen); imbvolgende.Enabled = true; ddlGebruikers.Items.Add(new ListItem("", "")); String ingelogdegebruikerid = (String)Session["gebruikerid"]; lbl1.Text = "Evaluator : " + Database.geefGebruikerNaam(ingelogdegebruikerid); IEnumerator<EvaluatieFormulier> evaluatieformulieren = Database.laadFormulierenIn().GetEnumerator(); List<EvaluatieFormulier> mijnformulieren = new List<EvaluatieFormulier>(); Session["mijnformulieren"] = mijnformulieren; while (evaluatieformulieren.MoveNext()) { if (((evaluatieformulieren.Current.GebruikerevaluatorID.ToString() == ingelogdegebruikerid) && (evaluatieformulieren.Current.Afgewerkt == "nee"))) mijnformulieren.Add(evaluatieformulieren.Current); } IEnumerator<EvaluatieFormulier> mijnenumerator = mijnformulieren.GetEnumerator(); while (mijnenumerator.MoveNext()) { String geevalueerdenaam = Database.geefGebruikerNaam(mijnenumerator.Current.GebruikergeevalueerdID); Boolean ziteralin = false; foreach (ListItem item in ddlGebruikers.Items) { if (item.Text == geevalueerdenaam) ziteralin = true; } if (!ziteralin) ddlGebruikers.Items.Add(new ListItem(geevalueerdenaam, mijnenumerator.Current.GebruikergeevalueerdID)); } imbFormulier.Visible = false; Session["formulieractief"] = false; } else { //Re-add the rating controls to my table IF the page is not being loaded for the first time && this boolean is true(the table is being shown) Boolean formulieractief = (Boolean)Session["formulieractief"]; if (formulieractief) { Evaluatieform mijnform = (Evaluatieform)Session["formulier"]; List<DomeinsCriteriums> domeincontrolenum = mijnform.controls; AjaxControlToolkit.Rating dynamischeratingcontrol = new AjaxControlToolkit.Rating(); dynamischeratingcontrol.FilledStarCssClass = "filledRatingStar"; dynamischeratingcontrol.EmptyStarCssClass = "emptyRatingStar"; foreach (DomeinsCriteriums domeincontrol in domeincontrolenum) { foreach (CriteriumLijn criteriumcontrol in domeincontrol.Criterias) { ScriptManager1.RegisterAsyncPostBackControl(dynamischeratingcontrol); dynamischeratingcontrol.ID = criteriumcontrol.Criterium.CriteriumNaam; dynamischeratingcontrol.MaxRating = Convert.ToInt32(criteriumcontrol.Criterium.Domein.DomeinGewicht); criteriumcontrol.Rating = dynamischeratingcontrol; criteriumcontrol.Rating.Changed += new AjaxControlToolkit.RatingEventHandler(rating_Changed); } } } }
}
The event handler that handles every event for each of the rating controls
//Event handler for each of the controls
protected void rating_Changed(object sender, AjaxControlToolkit.RatingEventArgs e)
{
AjaxControlToolkit.Rating gefirederatingcontrol = (AjaxControlToolkit.Rating) sender;
String ratingid = gefirederatingcontrol.ID;Evaluatieform mijnform = (Evaluatieform) Session["formulier"]; IEnumerator<DomeinsCriteriums> domeincontrolenum = mijnform.controls.GetEnumerator(); while (domeincontrolenum.MoveNext()) { foreach (CriteriumLijn criteriumcontrol in domeincontrolenum.Current.Criterias) { if (criteriumcontrol.Criterium.CriteriumNaam == ratingid) criteriumcontrol.Score = gefirederatingcontrol.CurrentRating; } } Session["formulier"] = mijnform;
}
The error on loading the page
Anyways, I get no errors what so ever in visual studio, but when I launch my website, and navigate to the page, even though he cant even execute the code when the page is opened(the table where the rating controls are to be added in is not visible so the boolean that lets me readd the controls on every page load is false), he gives me these compilation errors:
- Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
Compiler Error Message: CS0029: Cannot implicitly convert type
'System.Collections.Generic.List<DomeinsCriteriums>.Enumerator' to
'System.Collections.Generic.IEnumerator<DomeinsCriteriums>'
Source Error:
Line 334:
Line 335: Evaluatieform mijnform = (Evaluatieform) Session["formulier"];
Line 336: IEnumerator<DomeinsCriteriums> domeincontrolenum = mijnform.controls.GetEnumerator();
Line 337:
Line 338: while (domeincontrolenum.MoveNext())
Source File: e:\Website Werkend (07-04-11)\Evaluatie.aspx.cs Line: 336
I get the same error for line 58 if I dont comment it.
Does anybody have any idea on this? Im clueless.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
看起来像
ControlCollection.GetEnumerator()您调用的
返回非通用 IEnumerator。尝试
Looks like the
ControlCollection.GetEnumerator()
that you are calling returns a non-generic IEnumerator.Try
当您将此行更改
为
或时会发生什么
What happens when you change this line
To
or