c#中动态创建textbox并且从数据库中获取表中数据添加到textbox中

 1         private void FormLugOther_Load(object sender, EventArgs e)
 2         {
 3             foreach (string str in FormLug.FieldListLug1)
 4             {
 5                 try
 6                 {
 7                     Label label = new Label();
 8                     label.Text = str;
 9                     this.tableLayoutPanel1.Controls.Add(label);
10                     TextBox textbox = new TextBox();
11                     textbox.Name = "tb" + str;
12                     textbox.Text = FormLug.tbValue.Rows[0][str].ToString();
13                     this.tableLayoutPanel1.Controls.Add(textbox);
14                 }
15                 catch
16                 {
17                     return;
18                 }
19             }
20         }
View Code

 

posted @ 2014-11-30 20:02  xzh1993  阅读(1524)  评论(0编辑  收藏  举报