473,320 Members | 1,865 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Enum - ArrayList to DropDownList

I have the following Enum I would like to display in an <asp:DropDownList>
control. I have no problem getting the names to appear using the .GetNames
method. Thus, None, Male and Female appear in the drop down list as desired.

Pulbick Enum Gender
{
None = 0,
Male = 1,
Female = 2
}

What I want to achieve though is retrieve the assiciated number/id related
to each option so that I can save it to my database. How can I get the value
1, when Male is selected in the DropDownList control?

Thanks
Oct 30 '08 #1
1 4125
Hello greg,
I have the following Enum I would like to display in an
<asp:DropDownListcontrol. I have no problem getting the names to
appear using the .GetNames method. Thus, None, Male and Female appear
in the drop down list as desired.

Pulbick Enum Gender
{
None = 0,
Male = 1,
Female = 2
}
What I want to achieve though is retrieve the assiciated number/id
related to each option so that I can save it to my database. How can I
get the value 1, when Male is selected in the DropDownList control?

Thanks

You can use

(int)Enum.Parse(string, typof(Gender)))

To get the associated enum value.

Even better would be to bind not just the names to the dropdown, but the
name/valeu pairs of course, that would forego the whole parsing of strings
issue...
--
Jesse Houwing
jesse.houwing at sogeti.nl
Oct 30 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Jax | last post by:
I have an arraylist of objects. This arraylist is bound to a repeater. That repeater then creates a set of controls like so <asp:repeater id="garmentRepeater" runat="server"...
3
by: Billy Porter | last post by:
Greetings, If I populate an ArrayList with values from, let's say, the Keys enum: ArrayList a = new ArrayList(); a.Add(Keys.Home); a.Add(Keys.End); ....then how do I iterate through the...
2
by: Mark Heimonen | last post by:
I haven't worked with enum types that much, and I wrote the following code to bind a list of enums to a dropdownlist. Using CType(.Parse(GetType(ManagePointClassLibrary.Utils.Log.EventType),...
8
by: Patrick.O.Ige | last post by:
Hi All, I have a code below:- That Binds a DropDownList to a database using ArrayList. This code works well in ASP.NET webMatrix. But when i use it below in VS.NEt it gives me the error:-...
3
by: Arnold Schrijver | last post by:
I wrote a program that draws items to the screen and maintains a set of Offset values. There was a bug in the code, because objects were positioned wrongly. While debugging I found some peculiar...
3
by: sck10 | last post by:
Hello, I am trying to bind an arraylist to a FormView DropDownList control in the PreRender state. The error that I get is the following: Databinding methods such as Eval(), XPath(), and...
8
by: CK | last post by:
Hi All, Good morning. I had a quick question. I have a public Enum. During page load I want to loop thru the Enum and put those as items in an asp:dropdownList. Does anyone have any sample code to...
5
by: =?Utf-8?B?cm9kY2hhcg==?= | last post by:
he yall, does anyone know the best way to populate a dropdownlist from an enum list? thanks, rodchar
3
by: hufaunder | last post by:
Imagine you have a charting library that can draw lines, bars, floating bars, bands, etc. Lines and bars need only one input. Floating bars and bands need two inputs. There are two approaches: ...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.