I have three checkboxes in a GridView but the user can only select one checkbox. So if they select the first checkbox, I need to alert them them that they cannot select the other two.
<asp:GridView CssClass="tblResults" runat="server" ID="dgDetails"
OnRowDataBound="dgDetails_ItemDataBound"
DataKeyField="ID" AutoGenerateColumns="false"
AlternatingRowStyle-BackColor="#EEEEEE">
<HeaderStyle CssClass="tblResultsHeader" />
<Columns>
<asp:TemplateField HeaderText="Approved1">
<ItemTemplate>
<asp:CheckBox runat="server" ID="chkApproved1" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Approved2">
<ItemTemplate>
<asp:CheckBox runat="server" ID="chkApproved2" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Approved3">
<ItemTemplate>
<asp:CheckBox runat="server" ID="chkApproved3" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
code behind:
protected void dgDetails_ItemDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
GridView gv = sender as GridView;
Quote.QuoteDetails qd = e.Row.DataItem as Quote.QuoteDetails;
CheckBox chkApproved1 = e.Row.FindControl("chkApproved1") as CheckBox;
CheckBox chkApproved2 = e.Row.FindControl("chkApproved2") as CheckBox;
CheckBox chkApproved3 = e.Row.FindControl("chkApproved3") as CheckBox;
}
}
I tried using something like this in query:
$('#<%= chkApproved1.ClientID %>').change(function () {
if($(this).is(":checked")) {
}
});
But that causes the error:The name 'chkApproved1' does not exist in the current context.
So how can I check if the checkboxes in the GridView have been ticked?
Aucun commentaire:
Enregistrer un commentaire