同桌上课用手指进去了好爽_欧美丰满熟妇xxⅹⅹ性大i_成人av天天日天天拍拍_猛男gay帅男gay男男同志_欧美va天堂在线观看_人妻无码av中文系列三里桃花_亚欧免费无码在线观看_久久久精品国产亚洲av水_日韩在线免费看污污污_2021无码专区人妻系列日韩

首頁 優(yōu)化推廣 .net 關于CheckBoxList 中限制選擇數(shù)量 后臺取值問題

.net 關于CheckBoxList 中限制選擇數(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>無標題頁</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">&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(",");//此處里面為單引號

        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

服務熱線

153 8323 9821

功能和特性

價格和優(yōu)惠

網(wǎng)站和維護

推廣和優(yōu)化

微信服務號