about enum

  • Thread starter Thread starter Tony Johansson
  • Start date Start date
T

Tony Johansson

I fill a dropdownlist in this way
<asp:DropDownList id="DropdownOrderStatus" runat="Server">
<asp:ListItem>Submitted</asp:ListItem>
<asp:ListItem>Processed </asp:ListItem>
</asp:DropDownList>

and I have an enum that looks like this
public enum orderStatusType {Created, Submitted,Processed};

I fetch the control DropDownList in this way
DropDownList ddl =
(DropDownList)DetailsView1.FindControl("dropDownOrderStatus");
I get the text value in this way.
string text = ddl.Text; // So here it says Submitted

Now what I want is to convert the string value Submitted to integer 1
because Submitted is in position 2 in the enum
How can I do that ?

//Tony
 
El miércoles, 26 de febrero de 2014 17:18:47 UTC+1, Tony Johansson escribió:
I fill a dropdownlist in this way

<asp:DropDownList id="DropdownOrderStatus" runat="Server">

<asp:ListItem>Submitted</asp:ListItem>

<asp:ListItem>Processed </asp:ListItem>

</asp:DropDownList>



and I have an enum that looks like this

public enum orderStatusType {Created, Submitted,Processed};



I fetch the control DropDownList in this way

DropDownList ddl =

(DropDownList)DetailsView1.FindControl("dropDownOrderStatus");

I get the text value in this way.

string text = ddl.Text; // So here it says Submitted



Now what I want is to convert the string value Submitted to integer 1

because Submitted is in position 2 in the enum

How can I do that ?



//Tony

Check Enum.Parse method:
http://msdn.microsoft.com/es-es/library/essfb559(v=vs.110).aspx
 
I fill a dropdownlist in this way
<asp:DropDownList id="DropdownOrderStatus" runat="Server">
<asp:ListItem>Submitted</asp:ListItem>
<asp:ListItem>Processed </asp:ListItem>
</asp:DropDownList>

and I have an enum that looks like this
public enum orderStatusType {Created, Submitted,Processed};

I fetch the control DropDownList in this way
DropDownList ddl =
(DropDownList)DetailsView1.FindControl("dropDownOrderStatus");
I get the text value in this way.
string text = ddl.Text; // So here it says Submitted

Now what I want is to convert the string value Submitted to integer 1
because Submitted is in position 2 in the enum
How can I do that ?

While Enum.Parse() is one solution, you really ought to look at using a data
source (even a simple ObjectDataSource) behind your dropdowns. That way you
can display one value and have a behind-the-scenes value that you can get to
use in further processing, such as the numeric value behind your enum. Look
into the DisplayMember and ValueMember properties of DropDownList. (I think
that's what they're called.)
 
Back
Top