Enum to DropDownList

CodeKeep C# Feed Maggio 12th, 2008

Description: Read an Enum in a DropDownList with the correct value

Link: http://www.codekeep.net/snippets/de3f8eb0-9481-4f0d-8d15-e02e3156cf0d.aspx

        string[] Names;

        Names = Enum.GetNames(typeof(TypePage));

        IdTypePageDropDownList1.Items.Clear();

        for (int i = 0; i < Names.Length; i++)
        {
            IdTypePageDropDownList1.Items.Add(new ListItem(
                                                            Names[i],
                                                            ((int)Enum.Parse(typeof(TypePage), Names[i])).ToString()
                                                            )
                                             );
        }

  • .NET
1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading ... Loading ...

Comments are closed.

Trackback URI |