How to get a value of Selected item from a ChekboxList 1)first drag and drop a CheckBoxList on your webPage.
2)Add Some Items.
3)Drag and drop one Button.
After selecting Your items from Checkboxlist, Click on Button to get values or text selected by you. protected void Submit_Click(object sender, EventArgs e)
{
String str=null ;
for (int i = 0; i < CheckBoxList1.Items.Count ; i++)
{
if (CheckBoxList1.Items[i].Selected == true)
{
Response.Write (str = CheckBoxList1 .Items [i].Text .ToString ()+"<br>");
}
}
}
Dear SyedShakeer,
I wonder if this code snippet was tested.
Corrected Code:
foreach (ListItem chk in chkList.Items)
{
if (chk.Selected == true)
{
Response.Write(chk.Text);
}
}
Please do test your code before you post it.
Remember! DotNetFunda is growing and the World is watching you!
Thanks,
Dheeraj
Hi Deeraj
I tested My code before Posting.It is working fine.
Then i Thought the code will be useful for someone.
Thanks for giving commnent on my code.
The Code if fine, there is nothing wrong with. When you post your Code please use the code Tag so that everything will be formatted well.
Thanks for posting.