SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["erp"].ConnectionString);
con.Open();
string intero = "Select * from judete";
SqlCommand cmd = new SqlCommand(intero, con);
SqlDataReader rdr;
rdr = cmd.ExecuteReader();
while (rdr.Read())
{
CheckBoxList check = new CheckBoxList();
check.Visible = true;
check.Items.Add(new ListItem(rdr[1].ToString()));
Panel1.Controls.Add(check);
foreach (ListItem item in this.check)
{
}
I want to make a foreach in the checkboxlist but I get an error that I don’t have a checkboxlist check despite that I’m creating it.Do you have any idea why my checkboxlist check isn’t recognized? I’m using c# in an asp.net application.
Remove the
this.beforecheckin theforeachloop and add.Itemsafter it:Reasons:
checkis a local variable and not a member variable.Itemsof theCheckBoxList.