c# 在循环中添加标签,ID怎么处理
来源:百度知道 编辑:UC知道 时间:2024/05/27 17:14:50
显示时
for(int i=0;i<10;i++)
{
Label lab = new Label();
lab.ID = "lab" + i;
this.Controls.Add(lab);
}
获取时
Label lab = (Label)this.FindControl("lab1");
如果你只是显示内容,那还可以,虽然说并不方便,但是如果还有其他事件控制它的值,那不建议你这么做,每次提交都会初始化,建议用js方式。
你可以说说你想实现的目的,大家帮你想一个比较合适的解决方法。
DataBase db = new DataBase();
DataSet ds = db.Ds("select COLUMN_NAME from information_schema.columns where TABLE_NAME='Level'");
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
TextBox tb = new TextBox();
tb.ID = "txt" + ds.Tables [0].Rows[i][0].ToString();
this.Page.Form.Controls.Add(tb);
//this.form1.InnerHtml= "<br/>";
this.Page.Form.Controls.Add(new LiteralControl("<br/>"));
供参考
vb2005,winForm:
for i as integer=0 to 100
dim L as new la