我正在添加动态控件,并且我想在动态添加控件时增加 Label 中的值
代码:
private int controlCount
{
get
{
int val = 0;
try
{
val = (int)ViewState["ControlCount"];
}
catch (Exception e)
{
// handle exception, if required.
}
return val;
}
set { ViewState["ControlCount"] = value; }
}
protected void addnewtext_Click(object sender, EventArgs e)
{
int i = controlCount++;
for (int j = 0; j <= i; j++)
{
AddVisaControl ac = (AddVisaControl)Page.LoadControl("AddVisaControl.ascx");
Label lb = new Label();
string z = Convert.ToString(i + 1);
lb.Text = "Visa " + z;
rpt1.Controls.Add(lb);
lb.Attributes.Add("class", "style8");
rpt1.Controls.Add(ac);
rpt1.Controls.Add(new LiteralControl("<BR>"));
}
}
在下图中,我得到标签值,即(Visa 3)正在覆盖
有任何想法吗?