how to create mutiple control with same ID

  • Thread starter Thread starter wpy
  • Start date Start date
W

wpy

Hi,

Does anybody know how to create multiple control with same ID or name in
asp.net and request the controls's value in array form? For example the vb
control can have same same but with different index.

Thanks.
 
With .NET, control collections are gone (and for good reason too! ;) ). What
you can do is create an object collection and add the individual controls to
that collection and then modify them that way.

IE:

LinkButton lb1 = new LinkButton();
LinkButton lb2 = new LinkButton();
LinkButton lb3 = new LinkButton();
LinkButton lb4 = new LinkButton();

LinkButton[] linkbuttons = { lb1, lb2, lb3, lb4 };

foreach(LinkButton lb in linkbuttons)
{
lb.Text = "Hello There";
}

---or---
for(int i=0;i<linkbuttons.Length;i++)
{
linkbuttons.Text = "I am link button " + i.ToString();
}

HTH,

Bill P.
 
Back
Top