您的位置:首页 > 产品设计 > UI/UE

c# web 如何使用RequiredFieldValidator控件验证CheckBoxList

2011-06-17 19:15 671 查看
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="CheckboxlistDemo._Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script language="javascript" type="text/javascript">
function checkIssueType(source, args) {
var chkListaTipoModificaciones = document.getElementById('<%= IssueTypeCheckBox.ClientID %>');
var chkLista = chkListaTipoModificaciones.getElementsByTagName("input");
for (var i = 0; i < chkLista.length; i++) {
if (chkLista[i].checked) {
args.IsValid = true;
return;
}
}
args.IsValid = false;
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<table>
<tr>
<td>
<asp:CheckBoxList ID="IssueTypeCheckBox" runat="server" RepeatDirection="Horizontal">
<asp:ListItem Value="1">Hardware</asp:ListItem>
<asp:ListItem Value="2">Software </asp:ListItem>
<asp:ListItem Value="3">Mechanical</asp:ListItem>
<asp:ListItem Value="4">Others</asp:ListItem>
</asp:CheckBoxList>
</td>
<td>
<asp:CustomValidator ID="CustomValidator1" runat="server" ErrorMessage="*" ClientValidationFunction="checkIssueType"></asp:CustomValidator>
</td>
</tr>
<tr>
<td><asp:Button runat="server" ID="btn" Text="Submit"/></td>
<td> </td>
</tr>
</table>
</div>
</form>
</body>
</html>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息