Asp.Net CheckBoxList Selected checkbox id's getting using Jquery

Asp.Net CheckBoxList Selected checkbox id's getting using Jquery

Hi,

I am using .Net Framework 4.0 with Asp.Net C# along with Jquery v1.4.4 My problem is that how can i get no. of selected checkbox id's using jquery in comma seperated values? Below code runs successfully but on alert window i got undefined,undefined


Here's my Asp.Net Code:

  1.  <div>
  2.         <fieldset>
  3.             <legend>Multiple selection from CheckBoxList and show the selected checkbox id's</legend>
  4.             <asp:CheckBoxList ID="CheckBoxList" runat="server" ClientIDMode="Static" DataSourceID="sdsCheckBoxList"
  5.                 DataTextField="QualificationName" DataValueField="QulificationId">
  6.             </asp:CheckBoxList>
  7.             <asp:SqlDataSource ID="sdsCheckBoxList" runat="server" ConnectionString="<%$ ConnectionStrings:DataConnectionString %>"
  8.                 SelectCommand="SELECT [QulificationId], [QualificationName] FROM [DoctorQulification] ORDER BY [QulificationId]">
  9.             </asp:SqlDataSource>
  10.             <br />
  11.             <input id="btnCheckboxClick" name="btnCheckboxClick" type="button" value="Checkbox Click"
  12.                 onclick="btnCheckboxClicked()" />
  13.         </fieldset>
  14.     </div>

Here's my page.aspx.cs Code:

  1.  protected void Page_Load(object sender, EventArgs e)
  2.         {
  3.             if (!Page.IsPostBack)
  4.             {
  5.                 foreach (ListItem item in CheckBoxList.Items)
  6.                 {
  7.                     item.Attributes.Add("hiddenValue", item.Value);
  8.                 }
  9.             }
  10.         }

Here's my Jquery Code:

  1. var glbCheckBoxList = "";

  2. function btnCheckboxClicked() {

  3.     $('#CheckBoxList input:checkbox:checked').each(function () {

  4.         var checkBoxValue = $(this).parent().attr('hiddenValue');
  5.         glbCheckBoxList += checkBoxValue + ', ';
  6.     });
  7.     alert(glbCheckBoxList);
  8. }
Any idea ? 

Regards

Muhammad Atif Nadeem
Software Engineer
University of Karachi