asp.net - Multiple controls with the same ID '' were found. FindControl requires that controls have unique IDs -
update:
here observed:
if org.registrations.count = 1 txtbox.id "_registration0_0" string .... ....
if org.registrations.count = 2 act strange
txtbox.id "_registration2_0" txtbox.id "_registration2_1" after starts again _registration2_0
ps: dont have problem if count = 1
end update
the error messages says trying have duplicate id below creating dynamic textbox, see whats wrong in code?
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; (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); } } }
it seems if have multiple org.registrations end duplicate ids. @ usage of test variable below:
protected void gv_rowcreated(object sender, gridviewroweventargs e) { students org = (namespace.students )(e.row.dataitem); int test =0; foreach (registration reg in org.registrations) { test++; int _count = org.registrations.count; (int rowid = 0; rowid < _count; rowid++) { textbox txtbox = new textbox(); txtbox.id = "_registration" + e.row.rowindex + "_" + rowid + "_" + test.tostring(); txtbox.text = reg.name; e.row.cells[7].controls.add(txtbox); } } }
Comments
Post a Comment