populate multiple dropdownlist

Discussion in 'ASP .Net' started by sweetpotatop@yahoo.com, Aug 27, 2007.

  1. Guest

    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.
     
    , Aug 27, 2007
    #1
    1. Advertising

  2. 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.
    --
    Milosz


    "" wrote:

    > 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.
    >
    >
     
    =?Utf-8?B?TWlsb3N6IFNrYWxlY2tpIFtNQ0FEXQ==?=, Aug 27, 2007
    #2
    1. Advertising

  3. Guest

    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.


    On Aug 27, 4:28 pm, Milosz Skalecki [MCAD] <>
    wrote:
    > Hi there,
    >
    > Use FindControl method of the containing control. For instance, if dynamiccontrolsare added into a panel try:
    >
    > dd = CType(myPanelId.FindControl("dd" + CStr(i)), DropDownList)
    >
    > Should help.
    >
    > P.S. Remember dynamiccontrolshave to be recreated on every postback.
    > --
    > Milosz
    >
    >
    >
    > "" wrote:
    > > 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.- Hide quoted text -

    >
    > - Show quoted text -
     
    , Aug 28, 2007
    #3
  4. Good evening,

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

    Regards
    --
    Milosz


    "" wrote:

    > 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.
    >
    >
    > On Aug 27, 4:28 pm, Milosz Skalecki [MCAD] <>
    > wrote:
    > > Hi there,
    > >
    > > Use FindControl method of the containing control. For instance, if dynamiccontrolsare added into a panel try:
    > >
    > > dd = CType(myPanelId.FindControl("dd" + CStr(i)), DropDownList)
    > >
    > > Should help.
    > >
    > > P.S. Remember dynamiccontrolshave to be recreated on every postback.
    > > --
    > > Milosz
    > >
    > >
    > >
    > > "" wrote:
    > > > 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.- Hide quoted text -

    > >
    > > - Show quoted text -

    >
    >
    >
     
    =?Utf-8?B?TWlsb3N6IFNrYWxlY2tpIFtNQ0FEXQ==?=, Aug 28, 2007
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Viktor Popov

    populate DropDownList from DB

    Viktor Popov, Jul 28, 2004, in forum: ASP .Net
    Replies:
    12
    Views:
    10,032
    performanz87
    Feb 19, 2010
  2. Rui Macdonald
    Replies:
    2
    Views:
    834
    Brock Allen
    Apr 18, 2005
  3. mr2_93
    Replies:
    1
    Views:
    3,604
    mr2_93
    Oct 2, 2005
  4. PK9
    Replies:
    3
    Views:
    180
  5. Enjoy Life
    Replies:
    2
    Views:
    280
    Roland Hall
    Feb 23, 2005
Loading...

Share This Page