如何在表1中添加两列st是标签,第二列是文本框 [英] how to add two columns in table 1 st is lable and second columns is textbox

查看:85
本文介绍了如何在表1中添加两列st是标签,第二列是文本框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

foreach (string item in list)
            {

                for (int i = 0; i < 1; i++)
                {


                    TableRow row = new TableRow();
                    for (int j = 0; j < 1; j++) // Loop for Column
                    {
                        TableCell cell = new TableCell();


                        Label lbl = new Label();
                        lbl.Text = item;
                        cell.Controls.Add(lbl);



                        TextBox tb = new TextBox();
                        tb.ID = "txtBox1" + i.ToString();
                        RequiredFieldValidator reqfldVal = new RequiredFieldValidator();
                        reqfldVal.ID = "RequiredValidator" + i;
                        reqfldVal.ControlToValidate = "txtBox1" + i;
                        reqfldVal.ErrorMessage = "Not Empty";
                        reqfldVal.SetFocusOnError = true;
                        cell.Controls.Add(tb);
                        row.Cells.Add(cell);
                    }
                    k++;

                    table.Rows.Add(row);
                }
            }

推荐答案

foreach (string item in list)
            {
 
                for (int i = 0; i < 1; i++)
                {
 

                    TableRow row = new TableRow();
                    for (int j = 0; j < 1; j++) // Loop for Column
                    {
                        TableCell cell = new TableCell();
 
                        Label lbl = new Label();
                        lbl.Text = item;
                        cell.Controls.Add(lbl);
                        row.Cells.Add(cell);
 
                        cell = new TableCell();
                        TextBox tb = new TextBox();
                        tb.ID = "txtBox1" + i.ToString();
                        RequiredFieldValidator reqfldVal = new RequiredFieldValidator();
                        reqfldVal.ID = "RequiredValidator" + i;
                        reqfldVal.ControlToValidate = "txtBox1" + i;
                        reqfldVal.ErrorMessage = "Not Empty";
                        reqfldVal.SetFocusOnError = true;
                        cell.Controls.Add(tb);
                        row.Cells.Add(cell);
                    }
                    k++;
 
                    table.Rows.Add(row);
                }
            }


这篇关于如何在表1中添加两列st是标签,第二列是文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆