Solved

Displaying Enums

Posted on 2006-11-20
7
245 Views
Last Modified: 2010-04-16
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
0
Comment
Question by:JRockFL
7 Comments
 
LVL 29

Expert Comment

by:Nightman
ID: 17982547
Try Priority.ToString()
0
 
LVL 8

Author Comment

by:JRockFL
ID: 17982643
It still displays as an integer.
0
 
LVL 29

Expert Comment

by:Nightman
ID: 17982668
Try removing the eval statement.
0
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 
LVL 8

Author Comment

by:JRockFL
ID: 17982690
I need the eval to display the data, this is for ASP.NET.

0
 
LVL 22

Expert Comment

by:_TAD_
ID: 17983401
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
 
LVL 6

Accepted Solution

by:
e1v earned 500 total points
ID: 17985688
To get the name of an enum you can use Enum.GetName(type, value), like

Enum.GetName(typeof(Priority), 1) returns Low
0
 
LVL 8

Author Comment

by:JRockFL
ID: 17986873
e1v,

Thank you, that is exactly what I was looking for.
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question