- Web.config配置文件详解
- EVAL的使用方法
- php dd打印
- 做外链时,应该注意nofollow 属性!
- IIS7错误:服务器配置为将传递身份验证和内置帐户一起使用,以访问指定的物理路径...
- 矩阵号是什么
- ModelBuilder.Entity
- 网站分析及竞争对手的分析
- javascript中的this关键字到底是什么?
- 大型网站的SEO策略
邮箱:
手机:15383239821
.net 关于CheckBoxList 中限制选择数量 后台取值问题
A界面代码:
<%@ Page Language="C#" 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 id="Head1" runat="server">
<title>无标题页</title>
</head>
<script type="text/javascript">
function limit(cbl) {
var cbs = document.getElementByIdx("<%= CheckBoxList1.ClientID %>").getElementsByTagName_r("input");
var count = 0;
for (var i = 0; i < cbs.length; i++) {
if (cbs[i].type == "checkbox") {
if (cbs[i].checked) {
count++;
}
}
}
if (count > 3) {
cbl.checked = false;
alert("不能多于3项");
return;
}
}
</script>
<body>
<form id="form1" runat="server">
<div>
<asp:CheckBoxList ID="CheckBoxList1" runat="server" ForeColor="White" CellPadding="0"
CellSpacing="0" Height="70px">
<asp:ListItem Value="0"> Weekly email newsletter</asp:ListItem>
<asp:ListItem Value="1"> Sale and special offer updates</asp:ListItem>
<asp:ListItem Value="2"> Do not send me any more emails</asp:ListItem>
<asp:ListItem Value="3"> Do not send me any more emails</asp:ListItem>
<asp:ListItem Value="4"> Do not send me any more emails</asp:ListItem>
</asp:CheckBoxList>
<asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
</div>
</form>
</body>
</html>
B界面代码:
using System;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
foreach (ListItem li in CheckBoxList1.Items)
li.Attributes.Add("onclick", "limit(this)");
}
protected void Button1_Click(object sender, EventArgs e)
{
string EmailSendType = null;
int n = this.CheckBoxList1.Items.Count;
for (int i = 0; i < n; i++)
{
if (CheckBoxList1.Items[i].Selected)
{
if (EmailSendType != null)
EmailSendType += "," + CheckBoxList1.Items[i].Value;
else
EmailSendType = CheckBoxList1.Items[i].Value;
}
}
string[] str = EmailSendType.Split(",");//此处里面为单引号
foreach (string s in str)
{
if (s.Trim() != "")
{
if (s == "0")
{
Response.Write("aa0");
}
if (s == "1")
{
Response.Write("bb1");
}
if (s == "2")
{
Response.Write("cc2");
}
if (s == "3")
{
Response.Write("dd3");
}
}
Response.Write(s+"<br>");
}
}
}
-
2011-08-04一套.net窗体身份验证方案(解决了防止用户重复登陆,session超时等问题)
-
2023-07-30composer创建php8项目失败
-
2011-03-29ASP.NET前台代码绑定后台变量方法总结
-
2013-06-11在线用户实体缓存解决方案
-
2019-12-15在Excel中引用运算符
-
2019-12-05绩效考核的原则
