Reputation: 61
how can I assign dynamic name in loop for
Table tbl = new Table();
i am trying to make dynamic table in aspx page . but because of static name .it is overriding all the time .please advise ?
Upvotes: 0
Views: 41
Reputation: 184
I think you could use a repeater with a template of the information. See https://learn.microsoft.com/en-us/previous-versions/aspnet/x4s0xktt(v=vs.100)
Upvotes: 0
Reputation: 52280
Add each instance to the Controls collection for the page (or control if you're embedding it) and set the ID to something unique.
var names = new string[] { "Table1", "Table2" };
foreach (var name in names)
{
this.Controls.Add( new Table { ID = name } );
}
Upvotes: 1