I have added controls dynamically to a table in ASP .NET by letting user enter the required no of rows. The sample code of the addRow() function is:
HtmlTableCell cell_1 = new HtmlTableCell();
HtmlTableCell cell_2 = new HtmlTableCell();
l = new Label();
nomenclature = new TextBox();
unit = new TextBox();
row[i] = new HtmlTableRow();
label.Text = "" +(i+ 1);
cell_1.Controls.Add(l);
row[i].Controls.Add(cell_1);
nomenclature.TextMode = TextBoxMode.MultiLine;
nomenclature.Rows = 5;
nomenclature.Columns = 40;
nomenclature.ID="nomenclature"+i;
nomenclature.Text = "NA";
cell_2.Controls.Add(nomenclature);
row[i].Controls.Add(cell_2);
table_items.Controls.Add(row[i]);
Now after successfully adding the rows, when i refresh the page and again try to add new Rows, It gives me sameID ' nomenclature0 ' error.
Please help me regarding this,
Thanks in Advance,
I havent enough info about your code.
Two possible solutions:
1) Try this "table_items.Controls.Clear();" before call addRows Function.
2) if ispostback, dont fill table.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.