ASP.NET - get id from checkboxlist - Asked By msakt on 14-Jun-12 02:20 AM

in gridview edititem template have checkboxlist...during edit  show checkbox list if i chose particular checkboxlist

when i update i want get id from selected cn i get id from checkbox selected = true

for (int j = 0; j < chkGroupCategoryName.Items.Count; j++)

          if (chkCustomerCategoryName.Items[j].Selected == true)


Chintan Vaghela replied to msakt on 14-Jun-12 03:26 AM

Hi Frndz,


Functionality: Get Checklist box selected Item ID



Get Checklistbox Selected Item ID  using chklist.Controls collection






Full Logic:


for (int j = 0; j < chcklist.Items.Count; j++)


          if (chcklist.Items[j].Selected == true)


            string strID = chcklist.Controls[j].ClientID;  



Hope this helpful!





TSN ... replied to msakt on 14-Jun-12 05:12 AM


 firstly find the checkboxlist in the gridview by using the findControl .


here is the code


Int[] selectedCBLIndex =new int[10];

CheckBoxList cbList=(CheckBoxList)e.Row.FindControl(“MYCBList”);

foreach (ListItem item in cbList.Items)


      if (item.Selected)


        int thisIndex = CheckBoxList1.Items.IndexOf(item);






DL M replied to msakt on 14-Jun-12 09:00 AM

use below code
foreach(object itemChecked in checkedListBox1.CheckedItems)
   DataRowView castedItem = itemChecked as DataRowView;
   string comapnyName = castedItem["CompanyName"];
   int? id = castedItem["ID"];

read more info.