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:
- <div>
- <fieldset>
- <legend>Multiple selection from CheckBoxList and show the selected checkbox id's</legend>
- <asp:CheckBoxList ID="CheckBoxList" runat="server" ClientIDMode="Static" DataSourceID="sdsCheckBoxList"
- DataTextField="QualificationName" DataValueField="QulificationId">
- </asp:CheckBoxList>
- <asp:SqlDataSource ID="sdsCheckBoxList" runat="server" ConnectionString="<%$ ConnectionStrings:DataConnectionString %>"
- SelectCommand="SELECT [QulificationId], [QualificationName] FROM [DoctorQulification] ORDER BY [QulificationId]">
- </asp:SqlDataSource>
- <br />
- <input id="btnCheckboxClick" name="btnCheckboxClick" type="button" value="Checkbox Click"
- onclick="btnCheckboxClicked()" />
- </fieldset>
- </div>
Here's my page.aspx.cs Code:
- protected void Page_Load(object sender, EventArgs e)
- {
- if (!Page.IsPostBack)
- {
- foreach (ListItem item in CheckBoxList.Items)
- {
- item.Attributes.Add("hiddenValue", item.Value);
- }
- }
- }
Here's my Jquery Code:
- var glbCheckBoxList = "";
- function btnCheckboxClicked() {
- $('#CheckBoxList input:checkbox:checked').each(function () {
- var checkBoxValue = $(this).parent().attr('hiddenValue');
- glbCheckBoxList += checkBoxValue + ', ';
- });
- alert(glbCheckBoxList);
- }
Any idea ?
Regards
Muhammad Atif Nadeem
Software Engineer
University of Karachi