I have a checkbox and appears on each line of the GridView and I want to find the id of the checkbox that has been ticked.
Code for GridView:
<asp:GridView style="width:75%"
ID="gvCVRTDetails"
ShowHeaderWhenEmpty="true"
CssClass="tblResults"
runat="server"
OnRowDataBound="gvCVRTDetails_RowDataBound"
DataKeyField="ID"
AutoGenerateColumns="false"
allowpaging="false"
AlternatingRowStyle-BackColor="#EEEEEE">
<HeaderStyle CssClass="tblResultsHeader" />
<Columns>
<asp:BoundField DataField="Description" HeaderText="Checklist Items"></asp:BoundField>
<asp:TemplateField HeaderText ="Checked?" ItemStyle-HorizontalAlign="Center">
<ItemTemplate>
<asp:CheckBox ID="chkChecked" runat="server" onchange=UpdateCheckedBox(this,this.value)></asp:CheckBox>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
I tried using onchange=UpdateCheckedBox(this,this.value) and onchange=UpdateCheckedBox(this.id,this.checked) but it doesn't return the id.
I added a simple function so I can check the id of the checkbox:
function UpdateCheckedBox(id, checked) {
alert(id);
alert(checked);
}
If I use this.id the alert message is blank. If I use this is says [object htmlSpanElement]. Using this.checked or this.value just returns undefined
Aucun commentaire:
Enregistrer un commentaire