how to create mutiple control with same ID

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.
 
B

Bill Priess

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,906
Latest member
SkinfixSkintag

Latest Threads

Top