populate multiple dropdownlist

  • Thread starter Thread starter sweetpotatop
  • Start date Start date
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.
 
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.
 
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.
 
Good evening,

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

Regards
 
Back
Top