zoukankan      html  css  js  c++  java
  • 动态添加 控件 并获取值

    动态添加控件:

     protected void Button1_Click(object sender, EventArgs e)
        {
            int column = GridView1.HeaderRow.Cells.Count;//得到GridView1列的方法
            for (int i = 0; i < column; i++)
            {
                string txtID = "New"+GridView1.HeaderRow.Cells[i].Text.ToString();
                TextBox tmp = new TextBox();
                tmp.ID = txtID;
                Form.FindControl("TD2").Controls.Add(tmp);
              
            }

        }

    获取其值:

    protected void Button2_Click(object sender, EventArgs e)//递交
        {
            Hashtable ht = new Hashtable();
            string table_name = Label1.Text;
            string[] ak = Request.Form.AllKeys;
            for (int i = 0; i < Request.Form.Count; i++)
            {
                //只筛选出动态生成的三个控件的值  
                if (ak[i].IndexOf("New") > -1)
                {
                    string a = ak[i].Substring(3);
                    ht.Add(ak[i].Substring(3), SqlStringConstructor.GetQuotedString(Request.Form[i]));
                }
                   
            }

            db.Insert(table_name, ht);
            Gridview_Find();
        }

  • 相关阅读:
    2021 2月 构建之法读书笔记
    2021 2 7 体温登记App开发总结
    2021 2 3android开发学习笔记 8
    2021 2 2 android开发学习笔记 7
    2021 1月 梦断代码读后感
    2021 2 1 android开发学习笔记 6
    2021 1 31 Android开发 学习笔记 5
    2021 1 28 android开发学习笔记 4
    2021 1 27 android开发学习笔记3
    Java作业(一)
  • 原文地址:https://www.cnblogs.com/tongdengquan/p/6090642.html
Copyright © 2011-2022 走看看