Home All Groups Group Topic Archive Search About

can i assign a name for a control dynamically?

Author
25 Jan 2007 10:54 PM
miladhatam@gmail.com
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

Author
26 Jan 2007 1:46 AM
Klesh Wong
"miladha***@gmail.com" wrote:

> 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
>
>
try FindControl method.
Are all your drivers up to date? click for free checkup

Author
26 Jan 2007 12:29 PM
miladhatam@gmail.com
hi klesh
may i ask you just a bit explain how can i do that ?
thanks
Author
26 Jan 2007 2:56 PM
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
Author
26 Jan 2007 4:58 PM
miladhatam@gmail.com
thanks Ladislav
sorry i am not english
your help was correct and it is working now
thanks for your good help

Bookmark and Share

Post Thread options