国产一区黄,国产夫妻一区,免费在线观看黄色小视频,日本黄色免费在线,久亚洲精品不子伦一区,日99久9在线免费,亚洲欧美日韩国产精品b站在线看

主營(yíng)業(yè)務(wù):網(wǎng)站制作 網(wǎng)站優(yōu)化 小程序制作 石家莊網(wǎng)站制作網(wǎng)站建設(shè)有限公司歡迎您!
石家莊閃云網(wǎng)絡(luò)科技有限公司
客服熱線15383239821
如何讓自己的網(wǎng)站更有質(zhì)量?

.net 關(guān)于CheckBoxList 中限制選擇數(shù)量 后臺(tái)取值問題

發(fā)布時(shí)間:2010/10/13 17:33:13

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>無標(biāo)題頁(yè)</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項(xiàng)");
                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">&nbsp;Weekly email newsletter</asp:ListItem>
            <asp:ListItem Value="1">&nbsp;Sale and special offer updates</asp:ListItem>
            <asp:ListItem Value="2">&nbsp;Do not send me any more emails</asp:ListItem>
            <asp:ListItem Value="3">&nbsp;Do not send me any more emails</asp:ListItem>
            <asp:ListItem Value="4">&nbsp;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(",");//此處里面為單引號(hào)

        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

相關(guān)新聞推薦

在線客服 : 服務(wù)熱線:15383239821 電子郵箱: 27535611@qq.com

公司地址:石家莊市新華區(qū)九中街江西大廈4062

備案號(hào):冀ICP備2022000585號(hào)-4