zoukankan      html  css  js  c++  java
  • ASP.NET 后台动态生成CheckBOx控件并获取选中的值

    DataTable dtES = ExperienceShopInfo.getExperienceShopAll();
        CheckBox checkBox;
        public void CheckBoxNew()
        {
            for (int i = 0; i < dtES.Rows.Count; i++)
            {
                //Table table = new Table();
                //TableRow row = new TableRow();
                //TableCell cell = new TableCell();

                checkBox = new CheckBox();
                checkBox.AutoPostBack = true;
                checkBox.Text = dtES.Rows[i]["es_ShopName"].ToString();
                checkBox.ID = dtES.Rows[i]["es_No"].ToString();
                //checkBox.ID = "ck" + i;

                checkBox.CheckedChanged += eventFunction;//eventFuntion是事件处理的函数
                //cell.Controls.Add(checkBox);
                //row.Cells.Add(cell);
                //table.Rows.Add(row);
                this.Panel1.Controls.Add(checkBox);
            }
        }


        protected void eventFunction(object sender, EventArgs e)
        {
            for (int i = 0; i < this.Panel1.Controls.Count - 1; i++)
            {
                //CheckBox ckf = (CheckBox)Panel1.FindControl("ck" + i);
                CheckBox ckf = (CheckBox)Panel1.FindControl(dtES.Rows[i]["es_No"].ToString());

                if (ckf.Checked == true)
                {
                    // ckf.Checked = true;

                    //for (int j = 0; j < count[i]; j++)
                    //{

                    //CheckBox ckf1 = (CheckBox)Panel1.FindControl("ck" + i);
                    CheckBox ckf1 = (CheckBox)Panel1.FindControl(dtES.Rows[i]["es_No"].ToString());
                    ckf1.Checked = true;

                    Response.Write("<script>alert('" + ckf1.Text + "')</script>");
                    //}

                }
                else
                    if (ckf.Checked == false)
                    // CheckBox ckf = (CheckBox)Panel1.FindControl("ck"+i);
                    {
                        // ckf.Checked = true;
                        //for (int j = 0; j < count[i]; j++)
                        //{
                        //CheckBox ckf1 = (CheckBox)Panel1.FindControl("ck" + i);
                        CheckBox ckf1 = (CheckBox)Panel1.FindControl(dtES.Rows[i]["es_No"].ToString());
                        ckf1.Checked = false;
                        //}

                    }
            }

        }

  • 相关阅读:
    每周分享五个 PyCharm 使用技巧(一)
    深入理解 Python 中的上下文管理器
    Delphi中Chrome Chromium、Cef3学习笔记(四)
    DELPHI中自定义消息的发送和接收
    Delphi2010/XE2下隐藏程序系统任务栏的图标
    批处理经典入门教程!(从不懂到高手)第2/5页
    批处理经典入门教程!(从不懂到高手)1/5
    批处理taskkill运行结束不掉程序以及停留问题
    delphi EncdDecd.pas单元中Encoding方法出现#$D#$A的解决方法
    Delphi中Chrome Chromium、Cef3学习笔记(三)
  • 原文地址:https://www.cnblogs.com/wuhuisheng/p/2047791.html
Copyright © 2011-2022 走看看