datagird中绑定数据库字段显示问题,0、1显示为男女!!

来源:百度知道 编辑:UC知道 时间:2024/05/18 02:52:28
<asp:BoundColumn DataField="isMale" HeaderText="性别" ItemStyle-HorizontalAlign="center"
ItemStyle-Width="20px">
<ItemStyle HorizontalAlign="Center" Width="20px" />
</asp:BoundColumn>

我希望大家把解决办法说详细点,我看了很多,什么直接操作数据库:select case 性别
when 1 then '男'
when 0 then '女'
end as 性别
from tablea
还有ItemDataBound绑定等 我都没弄好,希望正确并说详细点!
刚做出来了

后台
public string GetSex(object obj)
{
int sextype = Convert.ToInt32(obj);
if (sextype == 0)
{
return "男";
}
else if (sextype == 1)
{
return "女";
}
else
{
return "不限";
}
}

前台
<asp:Label ID="Label1" runat="server" Text='<%# GetSex(Eval("sex")) %>'></asp:Label>