Convert DropDownList values to enum values

Discussion in 'ASP .Net' started by Andy B., Jun 8, 2009.

  1. Andy B.

    Andy B. Guest

    I have the following dropdownlist and enum. I want the listItem values for
    the dropdownlist to be the enums values. How do you do this?

    -- dropdownlist
    <asp:DropDownList ID="HeadlinesTypeDropDown" runat="server">

    <asp:ListItem Selected="True" Value="1">All</asp:ListItem>

    <asp:ListItem Value="2">Current</asp:ListItem>

    <asp:ListItem Value="3">Expired</asp:ListItem>

    </asp:DropDownList>



    --enum

    public enum HeadlineType

    All=1

    Current=2

    Expired=3

    end enum
     
    Andy B., Jun 8, 2009
    #1
    1. Advertising

  2. Hello Andy B.,

    > I have the following dropdownlist and enum. I want the listItem values
    > for the dropdownlist to be the enums values. How do you do this?
    >
    > <asp:ListItem Selected="True" Value="1">All</asp:ListItem>
    >
    > <asp:ListItem Value="2">Current</asp:ListItem>
    >
    > <asp:ListItem Value="3">Expired</asp:ListItem>
    >
    > </asp:DropDownList>
    >
    > --enum
    >
    > public enum HeadlineType
    >
    > All=1
    >
    > Current=2
    >
    > Expired=3
    >
    > end enum



    You can use

    HeadlineType value = (HeadlineType)Enum.Parse(string, typeof(HeadlineType))

    to do this.

    I'm unfamiliar with the exact VB.NET syntax though...

    I guess it would be somthing like:

    Dim value as HeadlineType = CType(Enum.Parse(string, typename(HeadlineType)),
    HeadlineType)

    --
    Jesse Houwing
    jesse.houwing at sogeti.nl
     
    Jesse Houwing, Jun 8, 2009
    #2
    1. Advertising

  3. On Jun 8, 4:07 pm, "Andy B." <> wrote:
    > I have the following dropdownlist and enum. I want the listItem values for
    > the dropdownlist to be the enums values. How do you do this?
    >
    > -- dropdownlist
    > <asp:DropDownList ID="HeadlinesTypeDropDown" runat="server">
    >
    > <asp:ListItem Selected="True" Value="1">All</asp:ListItem>
    >
    > <asp:ListItem Value="2">Current</asp:ListItem>
    >
    > <asp:ListItem Value="3">Expired</asp:ListItem>
    >
    > </asp:DropDownList>
    >
    > --enum
    >
    > public enum HeadlineType
    >
    > All=1
    >
    > Current=2
    >
    > Expired=3
    >
    > end enum


    Select Case HeadlinesTypeDropDown.Selected.Value
    Case HeadlineType. All
    Return "great"
    Case HeadlineType.Current
    Return "good"
    ....
     
    Alexey Smirnov, Jun 8, 2009
    #3
    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. -

    enum within an enum

    -, Jun 12, 2005, in forum: Java
    Replies:
    6
    Views:
    568
  2. Eric Sosman
    Replies:
    3
    Views:
    795
    Mayeul
    Feb 26, 2010
  3. Wojtek
    Replies:
    1
    Views:
    512
  4. Lew
    Replies:
    0
    Views:
    545
  5. Roedy Green
    Replies:
    0
    Views:
    743
    Roedy Green
    Feb 27, 2010
Loading...

Share This Page