?
Solved

Displaying Enums

Posted on 2006-11-20
7
Medium Priority
?
257 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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 2000 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
High user turnover can cause old/redundant user data to consume valuable space. UserResourceCleanup was developed to address this by automatically deleting user folders when the user account is deleted.
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Loops Section Overview
Suggested Courses

850 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