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;
                        //}

                    }
            }

        }

  • 相关阅读:
    Ldap遇到了事务管理问题
    Spring-Ldap连接Ldap及简单的增删查改
    枚举与数组的使用
    GDI_TCanvas
    获取鼠标当前位置的相对坐标、模拟鼠标点击事件
    绘制不规则图片、窗体与图形
    Message使用
    泛型_Tlist存储对象
    控件Owner和Parent的区别
    鼠标拖放
  • 原文地址:https://www.cnblogs.com/wuhuisheng/p/2047791.html
Copyright © 2011-2022 走看看