I have this CheckBoxList on a page:
Swapna, Your answer absolutely works. So in order to check if the check box in the ASP.Net Checkboxlist is checked and then accumulate the list as a comma-delimited string, you can do as
C# Code-behind
ChkboxList1.DataSource = dsData;
ChkboxList1.DataTextField = "your-display-column-name";
ChkboxList1.DataValueField = "your-identifier-column-name";
ChkboxList1.DataBind();
foreach (ListItem li in ChkboxList1.Items)
{
li.Attributes.Add("DataValue", li.Value);
}
Then in Javascript do
var selValues = "";
var ChkboxList1Ctl = document.getElementById("ChkboxList1");
var ChkboxList1Arr = null;
var ChkboxList1Attr= null;
if (ChkboxList1Ctl != null)
{
ChkboxList1Arr = ChkboxList1Ctl.getElementsByTagName("INPUT");
ChkboxList1Attr = ChkboxList1Ctl.getElementByTagName("span");
}
if (ChkboxList1Arr != null)
{
for (var i = 0; i < ChkboxList1Arr.length; i++)
{
if (ChkboxList1Arr[i].checked)
selValues += ChkboxList1Attr[i].getAttribute("DataValue") + ",";
}
if (selValues.length > 0)
selValues = selValues.substr(0, selValues.length - 1);
}