我有一个名为gv1
的网格视图。里面有复选框,必须检查至少1个复选框进行处理。我有自定义验证,但它无法正常工作。请看下面的,
自定义验证器
<asp:CustomValidator runat="server" ID="vldItemCus"
ClientValidationFunction="ValidateSelection"
Display="None" ErrorMessage="Select atleast one item for update" ValidationGroup="Update"></asp:CustomValidator>
验证摘要
<asp:ValidationSummary ID="vldSummary" runat="server" ShowMessageBox="True" ShowSummary="False" ValidationGroup="Update"></asp:ValidationSummary>
Javascript功能
function ValidateSelection(source, args) {
var found = 0;
$('#gv1 input[type=checkbox]').each(function () {
if (this.checked) {
found = 1;
return false;
}
});
if (found == 1) {
args.IsValid = true;
}
else {
args.IsValid = false;
}
return;
}
答案 0 :(得分:1)
更改功能如下,
function ValidateSelection(source, args) {
var found = 0;
$('#<%= gv1.ClientID %> input[type=checkbox]').each(function () {
if (this.checked) {
found = 1;
return false;
}
});
if (found == 1) {
args.IsValid = true;
}
else {
args.IsValid = false;
}
return;
}