在asp中绑定数据源时
如果某个字段在数据库值为0,1等,但却想显示其代表的正确文字型的含义
可做如下转换(以”TestPaperType“为例)
前台写法:
<asp:Label ID="TestPaperType" runat="server" Text='<%# Type(DataBinder.Eval(Container.DataItem, "TestPaperType"))%>' Width="150px"></asp:Label>
后台写法:
//套餐类型(用于哪方用户)
public string Type(object tmp)
{
if (Convert.ToInt32(tmp.ToString()) == 0)
{
return "需求方";//你想显示的文字
}
else if (Convert.ToInt32(tmp.ToString()) == 1)
{
return "服务方";
}
return "无类型";
}