【发布时间】:2011-01-25 18:58:30
【问题描述】:
更新:
这是我观察到的:
if i get org.Registrations.Count = 1 then
txtBox.ID "_registration0_0" string
....
....
如果我得到 org.Registrations.Count = 2 那么它的行为很奇怪
txtBox.ID "_registration2_0"
txtBox.ID "_registration2_1"
after that i starts again with _registration2_0
ps:如果count = 1,我没有问题
结束更新
错误消息清楚地表明我正在尝试重复 id 但下面是我创建动态文本框的地方,你看到我的代码有什么问题吗?
protected void gv_RowCreated(object sender, GridViewRowEventArgs e)
{
Students org = (namespace.Students )(e.Row.DataItem);
foreach (Registration reg in org.Registrations)
{
int _count = org.Registrations.Count;
for (int rowId = 0; rowId < _count; rowId++)
{
TextBox txtBox = new TextBox();
txtBox.ID = "_registration" + e.Row.RowIndex + "_" + rowId;
txtBox.Text = reg.Name;
e.Row.Cells[7].Controls.Add(txtBox);
}
}
}
【问题讨论】:
-
您是否调试过代码,它是否为每列返回唯一 ID?我关心 Row.RowIndex ,这就是我要问的原因。调试代码并为这些设置监视值。