码迷,mamicode.com
首页 > 其他好文 > 详细

20151215:练习:全选

时间:2015-12-21 00:08:59      阅读:143      评论:0      收藏:0      [点我收藏+]

标签:

protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            TextDataContext context = new TextDataContext();
            CheckBoxList1.DataSource = context.Nation;
            CheckBoxList1.DataTextField = "Name";
            CheckBoxList1.DataValueField = "Code";
            CheckBoxList1.DataBind();
        }
    }
    protected void CheckBox1_CheckedChanged(object sender, EventArgs e)
    {
        //设置点击全选和取消全选
        foreach( ListItem item in CheckBoxList1.Items )
        {
            item.Selected = CheckBox1.Checked;
        }
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        //取值
        string zhi = "";
        foreach( ListItem item in CheckBoxList1.Items )
        {
            if(item.Selected)
            {
                zhi += item.Value.ToString()+",";//用,分割
            }
        }
        //去掉最后多余的逗号
        zhi = zhi.Substring(0, zhi.Length - 1);
        //拆分字符串,把选中的每一项都弹出一个窗体
        string[] codes;
        codes = zhi.Split(,);
        //造js代码
        string js = "<script type=‘text/javascript‘>";

        for (int i = 0; i < codes.Length; i++)
        {
            js += "alert(‘"+codes[i]+"‘);";
        }

        js += "</script>";

        Literal1.Text = js;
            //弹出一个窗体,显示选中的值,借助一个工具Literall,在Literall中写js代码
            //Literal1.Text = "<script type=‘text/javascript‘>alert(‘" + zhi + "‘)</script>";

    }

技术分享技术分享

 

20151215:练习:全选

标签:

原文地址:http://www.cnblogs.com/mn-b/p/5062228.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!