i added checkboxes dynamically to panel.
for (int intControlIndex = 0; intControlIndex < dsTagsList.Tables[0].Rows.Count; intControlIndex++)
{
chkList1 = new CheckBox();
chkList1.Text = dsTagsList.Tables[0].Rows[intControlIndex][0].ToString();
chkList1.ID = "Chk" + intControlIndex;
chkList1.Font.Name = "Verdana";
chkList1.Height = 20;
chkList1.ForeColor = System.Drawing.Color.Black;
chkList1.Font.Size = 10;
panelTags.Controls.Add(chkList1);
panelTags.Controls.Add(new LiteralControl("<br>"));
}
How to check which checkboxes selected or not ?
Please tell me….
I would loop through all controls in the panel, check if the control is a check box, then act on it if it is.
Or better yet, using LINQ
OfTypethat filters an enumerable by type:The LINQ statement lets us further query the list.
If you only want to act on checked checkboxes.
A few other things I can think of that may be causing problems:
Is the
foreachis being called beforePage_Load? Since you’re likely running this in a postback, thePage_Loadis when the control properties are loaded with information recovered from view state and control state.Is the checkbox creation within a
if(!IsPostBack)to prevent multiple controls from being added?Are you calling
panelTags.Controls.Clear();before adding the checkboxes this will remove any data returned from the page>