I have 2 checkboxes in a GridView. I want to validate them with JavaScript. This is my aspx code...
<asp:TemplateField HeaderText="IsExist">
<ItemTemplate>
<asp:CheckBox ID="chkExists" runat="server" Text="Exists" AutoPostBack="false" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Not Exists In Update">
<ItemTempl开发者_JAVA技巧ate>
<asp:CheckBox ID="chkExistsInUpdate" runat="server" Text="NotExists" AutoPostBack="false"/>
</ItemTemplate>
</asp:TemplateField>
And my JavaScript condition is:
function check_one() {
var obj = document.form1;
if (obj.chkExists.checked == true || obj.chkExistsInUpdate.checked == true) {
alert("Plese check only one checkbox...");
return false;
}
else
return true;
}
But I don't know that how to access the checkboxes from GridView on the client side? Please suggest an example.
MyGridView = document.getElementById('<%= this.MyGridView.ClientID %>');
var Inputs = MyGridView.getElementsByTagName("input");
var chkBox = "chkExists";
for(var n = 0; n < Inputs.length; ++n)
if(Inputs[n].type == 'checkbox' &&
Inputs[n].id.indexOf(chkBox,0) >= 0 &&
Inputs[n].checked)
return true;
Similarly you can check for the other checkbox too...
精彩评论