Displaying Enums

Here is my code...

public enum Priority
    {
        Low =1, Medium = 2, High = 3
    }


<asp:TemplateField HeaderText="Priority">
    <ItemTemplate>
        <%#(Eval("Priority")) %>
    </ItemTemplate>
</asp:TemplateField>

Right now the Priority displays as a number i.e., 1
I would like for it to display "Low" instead
LVL 8
JRockFLAsked:
Who is Participating?
 
e1vConnect With a Mentor Commented:
To get the name of an enum you can use Enum.GetName(type, value), like

Enum.GetName(typeof(Priority), 1) returns Low
0
 
NightmanCTOCommented:
Try Priority.ToString()
0
 
JRockFLAuthor Commented:
It still displays as an integer.
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
NightmanCTOCommented:
Try removing the eval statement.
0
 
JRockFLAuthor Commented:
I need the eval to display the data, this is for ASP.NET.

0
 
_TAD_Commented:
All enums resolve to an integer representation.  The only reason an enum has a text value associated with it is to assist the developer.

If you really want the enum name, you'll need to use reflections to inspect the enum itself and then translate the result to a reflected text value
0
 
JRockFLAuthor Commented:
e1v,

Thank you, that is exactly what I was looking for.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.