can i assign a name for a control dynamically?

M

miladhatam

hi ladies and gentlemen
how can i call a control dynamically?
for example
for(i=1;i<10;i++) {
"label" + i + ".text" =i*2;
}
thanks
 
L

Ladislav Mrnka

I don't understand what you mean by 'assign a name for control dynamically'
but if you want to construct id of your controls as a string you should use
FindControl as follows.

for (int i = 1; i < 10; i++)
{
Label lb = Page.FindControl(String.Format("label{0}", i)) as Label;

if (lb != null)
{
lb.Text = i * 2;
}
}

Regards,
Ladislav Mrnka
 
M

miladhatam

thanks Ladislav
sorry i am not english
your help was correct and it is working now
thanks for your good help
 

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
474,083
Messages
2,570,591
Members
47,212
Latest member
RobynWiley

Latest Threads

Top