标签名称在运行时更改 [英] Label name change in runtime

查看:84
本文介绍了标签名称在运行时更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Table table = new Table();
table.ID = "Table1";
Page.Form.Controls.Add(table);




听到Creting 10 lables id正在生成0,1,2 .... 10.我需要如何将0更改为Name1,将2更改为name2 ....




Hear Creting 10 lables id is generating 0,1,2....10. i need how to change the 0 to Name1, 2 to name2 ....

推荐答案

//Hear Creting 10 lables id正在生成0,1, 2 .... 10.我需要如何将0更改为Name1,将2更改为name2 ....
放在这里:
//Hear Creting 10 lables id is generating 0,1,2....10. i need how to change the 0 to Name1, 2 to name2 ....
Place this there:
lbl.ID = "Name"+ (i+1).ToString();




您要更改名称的地方
Hi,

Where you want to change the Name
Lable lb=[table].FindControl(ControlID);
lb.ID= [ Change To your Custom ID]
</pre>


您好使用此代码.........

Hello use this code .........

Table table = new Table();
        table.ID = "Table1";
        Page.Form.Controls.Add(table);

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

                Label lbl = new Label();
                lbl.ID = "Name"+(i+1); // This is first method id like--> Name1,Name2 etc.  
   // lbl.ID = "Name"+(i+1)+ "_" + j.ToString(); // This is Second method id like--> Name1_0,Name2_1 etc.
                lbl.Text = i.ToString();
                cell.Controls.Add(lbl);

                //Hear Creting 10 lables id is generating 0,1,2....10. i need how to change the 0 to Name1, 2 to name2 ....

                TextBox tb = new TextBox();
tb.ID = "txtBox1" + i.ToString();
                //tb.ID = "Name" + (i+1); // U can use for text box Id
                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);
            }

            table.Rows.Add(row);
        }


这篇关于标签名称在运行时更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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