Wednesday, July 6, 2011

To retrieve the value of dynamic generate Checkbox when it get checked in asp.net

//First Create the object of CheckBoxList
CheckBoxList chk=new CheckBoxList();
ck.Item.Add("cricket");
ck.Item.Add("hockey");
ck.Item.Add("badminton");
ck.Item.Add("table tennis");
ck.Item.Add("rugby");
ck.AutoPostBack=true; //postback occur when checkbox is checked
form1.Controls.Add(ck);
ck.selectedIndexChanged +=new EventHandler(chkvalue);

protected void chkvalue(object sender,EventArgs e)
{
int a=ck.Items.Count; // count no of item in checkboxlist
for(int i=0;i<a;i++)
{
it(ck.Item[i].selected)
{
Response.Write(ck.Item[i].Text);
}
}
}

Display the value of checkbox when it get checked

No comments:

Post a Comment