编辑:
这是一个示例代码。它对我有用
必须添加此脚本文件:<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_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 src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript">
function Validate_Checkbox() {
var chks = $("#<%= cblCustomerList.ClientID %> input:checkbox");
var hasChecked = false;
for (var i = 0; i < chks.length; i++) {
if (chks[i].checked) {
hasChecked = true;
break;
}
}
if (hasChecked == false) {
alert("Please select at least one checkbox..!");
return false;
}
return true;
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:CheckBoxList ID="cblCustomerList" runat="server" CssClass="CheckBoxList">
<asp:ListItem Value="0">xx</asp:ListItem>
<asp:ListItem Value="1">yy</asp:ListItem>
</asp:CheckBoxList>
<asp:Button ID="xx" runat="server" OnClientClick="javascript:Validate_Checkbox();return true;" />
</div>
</form>
</body>
</html>
你改变了
<asp:CheckBoxList ID="cblCustomerList" runat="server" DataSourceID="SqlDataSource1" CssClass="CheckBoxList" DataTextField="GroupName" DataValueField="GroupName">
</asp:CheckBoxList>
控制而不是我的示例代码。并javascript function
在按钮控件中调用。看看我的示例代码。
雪儿!!!
编辑
请添加此脚本文件
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
代替<script src="scripts/jquery-1.8.3.min.js" type="text/javascript"></script>