0

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:

  1. 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);
                }
            }
        }
    }        
    

    }

  2. 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;
    

    }

  3. 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.

2 Answers 2

0

Looks like the ControlCollection.GetEnumerator() that you are calling returns a non-generic IEnumerator.

Try

Evaluatieform mijnform = (Evaluatieform) Session["formulier"];
IEnumerator domeincontrolenum = mijnform.controls.GetEnumerator();

while (domeincontrolenum.MoveNext())
{
    DomeinsCriteriums current = (DomeinsCriteriums)domeincontrolenum.Current;
    foreach (CriteriumLijn criteriumcontrol in current.Criterias)
    {
        if (criteriumcontrol.Criterium.CriteriumNaam == ratingid)
            criteriumcontrol.Score = gefirederatingcontrol.CurrentRating;
    }
}
0

What happens when you change this line

IEnumerator<DomeinsCriteriums> domeincontrolenum = mijnform.controls.GetEnumerator();

To

List<DomeinsCriteriums>.Enumerator domeincontrolenum = mijnform.controls.GetEnumerator();

or

var domeincontrolenum = mijnform.controls.GetEnumerator();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.