to get ids from CheckBoxList

Posted by Amritha444 under C# on 11/13/2010 | Points: 10 | Views : 4149 | Status : [Member] | Replies : 3
I assigned value and text to the CheckBoxList.Want to get ids of selected items .Can any body suggest good idea to get ids of selected items.

Thanks in advance




Responses

Posted by: Raja on: 11/13/2010 [Member] Starter | Points: 25

Up
0
Down
If your checkbox is something like this.

<asp:CheckBoxList runat="server" id="chkList"></asp:CheckBoxList>


You will get the selected id by doing this.


chkList.SelectedValue; // to get the selected value

chkList.SelectedItem.Value; // to get the selected value

chkList.SelectedItem.Text; // to get the selected text


To get all selected checkboxes

foreach (ListItem item in chkList.Items)

{
if (item.Selected)
{
string value = item.Value; // will get all that is checked, you can concatenate here
}
}


Thanks

Regards,
Raja, USA

Amritha444, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Gokul on: 12/8/2010 [Member] Starter | Points: 25

Up
0
Down
Give a unique id for checklist as chklst. when u code in .cs file when you type the c hk letters the intelligence will tell you all the available id's starting with chk. You can choose yours from it.


cheers
Gokul.N


Thanks and Regards,
GokulNath Nithy.

Amritha444, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Lalji_mer on: 12/15/2010 [Member] Bronze | Points: 25

Up
0
Down
Hi,

You will get here solution try this link
http://stackoverflow.com/questions/1640374/checkboxlist-getting-ids-of-all-the-checkboxes

LP MER

Amritha444, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response