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

                    }
            }

        }

  • 相关阅读:
    TreeSet类的排序问题
    TreeSet()详解
    css中vertical-align垂直居中的认识
    CSS3 float深入理解浮动资料整理
    层叠顺序与层叠上下文
    jquery.zclip轻量级复制失效问题
    文章转载利用border、transparent实现微风
    转载利用线性渐变实现晴天、多云特效
    转载利用伪元素单个颜色实现 hover 和 active 时的明暗变化效果
    MUI-最接近原生App体验的前端框架
  • 原文地址:https://www.cnblogs.com/wuhuisheng/p/2047791.html
Copyright © 2020-2023  润新知