i need to display the name of enum in gridview by data table returns its numeric value
i am using this for other columns
<asp:BoundField DataField="Name" HeaderText="User Name" />
i need to use it for enum to display the string value of enum Gender
<asp:BoundField DataField="Gender" HeaderText="Gender" />
Try this solution
Enum.GetName Method
<asp:TemplateField HeaderText="Category">
<ItemTemplate>
<div>
<%# Enum.GetName(typeof(GlobalLibrary.Constants.Category),Convert.ToInt32(Eval("Category"))) %>
</div>
</ItemTemplate>
</asp:TemplateField>
It helped me :) And then I found this simpler
<asp:TemplateField HeaderText="Gender">
<ItemTemplate><%#(MyGenderEnum)Eval("Gender")%></ItemTemplate>
</asp:TemplateField>
And if you prefer VB.NET:
<asp:TemplateField HeaderText="Status" SortExpression="VisibilityStatus">
<ItemTemplate>
<%# [Enum].GetName(GetType(VisibilityStatusEnum), Eval("VisibilityStatus"))%>
</ItemTemplate>
</asp:TemplateField>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With