在GridView控件格式枚举 [英] formatting enum in gridview

查看:114
本文介绍了在GridView控件格式枚举的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要显示的GridView枚举的名字
通过数据表格返回其数值

我用这对其他列

 < ASP:BoundField的数据字段=名称的HeaderText =用户名/>

我需要用它来枚举显示枚举性别的字符串值

 < ASP:BoundField的数据字段=性别的HeaderText =性别/>


解决方案

尝试这种解决方案

Enum.GetName方法

 < ASP:的TemplateField的HeaderText =类别>
<&ItemTemplate中GT;
< D​​IV>
<%#Enum.GetName(typeof运算(GlobalLibrary.Constants.Category),Convert.ToInt32(EVAL(类别)))%GT;
< / DIV>
< / ItemTemplate中>
< / ASP:的TemplateField>

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>

这篇关于在GridView控件格式枚举的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆