vendredi 25 novembre 2016

Cant Bind Panel with session in code behind, Collection was modified; enumeration operation may not execute

I have repeater control in that few repeater item bind with check box and few with Radio button while cheeked any radio button or check box I need to display that in one panel [ PanelRadio ] for radio button text and panel [PanelCheckBox] for check box option. but while I trigger a radio button I cant bind control for PanelCheckBox, for that am saving bind PanelCheckBox in one session and bind that in PanelRadio check event. but it shows ' Collection was modified; enumeration operation may not execute '

        CheckBox box = (CheckBox)sender;
        RepeaterItem item1 = box.NamingContainer as RepeaterItem;
        Repeater RptTopic = (Repeater)item1.NamingContainer;

        foreach (RepeaterItem item in RptTopic.Items)
        {
            CheckBox rbtn = (CheckBox)item.FindControl("custChkbx");
            Label disc = (Label)item.FindControl("CustTopic");
            if (rbtn.Checked)
            {
                Label lbl = new Label();
                lbl.Text = disc.Text;
                HtmlGenericControl div = new HtmlGenericControl("div");
                div.Controls.Add(lbl);
                Panel1.Controls.Add(div);
            }

        }
        Session.Add("DisOption", Panel1);
        if (Session["DisROption"] != null)
        {
            Panel z = (Panel)Session["DisROption"];
            foreach (Control child in z.Controls)    // Getting Error here
            {
                PanelCheckBox.Controls.Add(child);
            }
        }

** DisROption option session add while trigger a Check box event. **




Aucun commentaire:

Enregistrer un commentaire