方法1:
Select
CASE
sex
WHEN
'
1
'
THEN
'
男
'
WHEN
'
0
'
THEN
'
女
'
ELSE
'
不男不女?哈哈
'
END
AS
sex
from
testname

if
(e.Row.Cells[列的索引].Text
==
"
0
"
)

...
{
e.Row.Cells[列的索引].Text="男";
}
else

...
{
e.Row.Cells[列的索引].Text="女";
}
<
asp:TemplateColumn
HeaderText
="性别"
>
<
ItemTemplate
>
<
asp:Label
runat
="server"
Text
='<%#
DataBinder.Eval(Container, "DataItem.Sex").ToString()
="1"
?"男":"女" %
>
' ID="Label1">
</
asp:Label
>
</
ItemTemplate
>
</
asp:TemplateColumn
>
protected
string
showSex(
int
temp)
...
{

if (temp == 1) ...{
return "男";}

else...{
return "女";
}
}
<
asp:TemplateField
HeaderText
="性别"
>
<
ItemTemplate
>
<
asp:Label
ID
="F_Sex"
runat
="server"
Text
='<%#
showSex(Convert.ToInt32(Eval("F_Sex"))) %
>
'>'>
</
asp:Label
>
</
ItemTemplate
>










方法2:
在RowDataBound中处理











方法3:模板列(sex == "1"?"男":"女")
用模板列:







注意:
如果字段为BIT <%# (bool)Eval("sex") ? "男" : "女" %>
如果是char <%# DataBinder.Eval(Container.DataItem,"Sex").ToString()=="1"?"男":"女" %>
方法4:自定义函数
cs文件中:前台:

















转载自菩提树下的杨过