populate multiple dropdownlist

S

sweetpotatop

Hi,

I am try to populate a number of dropdownlist with the same item,

for i = 1 to 5
dd = me.controls("dd" + Cstr(i))

itm = new listiem
itm.text ="abc"
itm.value ="aaa"

dd.add(itm)

next i
But I am getting the following error
"Conversion from string "dd1" to type 'Integer' is not valid"
when it hits this line.
dd = me.controls("dd" + Cstr(i))

Please help. I just wonder how I can refer to a control to a page
dynamically

Thanks in advance.
 
G

Guest

Hi there,

Use FindControl method of the containing control. For instance, if dynamic
controls are added into a panel try:

dd = CType(myPanelId.FindControl("dd" + CStr(i)), DropDownList)

Should help.

P.S. Remember dynamic controls have to be recreated on every postback.
 
S

sweetpotatop

Thanks for the advice, actually, all controls exit already, it is just
a matter that I need to make them visible. I tried to your suggested
syntax, but it doesn't work, it just retrun nothing.

Please advice and thanks in advance.
 
G

Guest

Good evening,

Could you please paste entire code so we could have a look what exactly have
been done.

Regards
 

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,755
Messages
2,569,537
Members
45,024
Latest member
ARDU_PROgrammER

Latest Threads

Top