Dropdownlist

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Ana Rita

    #1

    Dropdownlist

    Hello to all.

    I´m trying to use a string, to build the ListItem's of a
    DropDownList.

    I declare a Public str as string in the webform1.aspx.v b,
    and in the page load I build the string like this:

    str = "<asp:ListI tem value='0'>Blue</asp:ListItem>
    <asp:ListItem value='1'>Red</asp:ListItem>"

    In the webform1.aspx, html mode, I call the str within the
    tag <asp:DropDownLi st>, like this <%str%>. As I expected,
    it gives an error, saying that I can't use this type of
    calls.

    I want to Know, if it's possible to do something like we
    do in asp to build a select object using a string with the
    <options>.

    Thank you all.

    Best wishes.

    Ana Rita



  • Patrick Steele [MVP]

    #2
    Re: Dropdownlist

    In article <1de701c372f7$e ccf6810$a401280 a@phx.gbl>, gatarita@clix.p t
    says...[color=blue]
    > Hello to all.
    >
    > I´m trying to use a string, to build the ListItem's of a
    > DropDownList.
    >
    > I declare a Public str as string in the webform1.aspx.v b,
    > and in the page load I build the string like this:
    >
    > str = "<asp:ListI tem value='0'>Blue</asp:ListItem>
    > <asp:ListItem value='1'>Red</asp:ListItem>"
    >
    > In the webform1.aspx, html mode, I call the str within the
    > tag <asp:DropDownLi st>, like this <%str%>. As I expected,
    > it gives an error, saying that I can't use this type of
    > calls.
    >
    > I want to Know, if it's possible to do something like we
    > do in asp to build a select object using a string with the
    > <options>.[/color]

    Your DropDownList should be a server-side control (has the
    "runat=serv er" attribute). If so, you should be able to simply access
    the "Items" collection and add to it. Example:

    <asp:DropDownLi st runat="server" id="colorList" />

    In code you should be able to do:

    colorList.Items .Add("Red")
    colorList.Items .Add("Blue")

    --
    Patrick Steele
    Microsoft .NET MVP

    Comment

    Working...