如何在Gridview DataBinder asp.net c#中绑定文本?
我在Gridview中显示我的表值,在数据库的状态列中,我将值分别存储为'Y'和'N'表示'Active'和'Inactive'。但是,在Gridview中显示时,我希望将状态显示为Active和InActive,而不是Y和N如何在Gridview DataBinder asp.net c#中绑定文本?,c#,asp.net,gridview,data-binding,C#,Asp.net,Gridview,Data Binding,我在Gridview中显示我的表值,在数据库的状态列中,我将值分别存储为'Y'和'N'表示'Active'和'Inactive'。但是,在Gridview中显示时,我希望将状态显示为Active和InActive,而不是Y和N <asp:Label ID="lblmerstatus" runat="server" Text= '<%# DataBinder.Eval(Container, "DataItem.STATUS") == "Y" ? "Active" : "InActiv
<asp:Label ID="lblmerstatus" runat="server" Text= '<%# DataBinder.Eval(Container, "DataItem.STATUS") == "Y" ? "Active" : "InActive"%>'></asp:Label>
但它总是只显示非活动状态,即使状态为Y。请帮助尝试使用
<asp:Label ID="lblmerstatus" runat="server"
Text= '<%# DataBinder.Eval(Container, "STATUS").ToString() == "Y" ? "Active" : "InActive"%>' ></asp:Label>
使用这可能会对您有所帮助
<asp:Label ID="lblmerstatus" runat="server" Text'<%# Convert.ToBoolean(Eval("Status")) %>'
Text='<%# Eval("Status").ToString().Equals("True") ? "Active" : "InActive" %>' />
现在使用这可能会帮助您 解决方案1:如果表字段“STATUS”返回布尔值,如true(1)或false(0):
解决方案2:如果表字段“STATUS”返回Y或N这样的字符串值:
<asp:Label ID="Label1" runat="server" Text='<%# Convert.ToString(Eval("STATUS")) == "Y" ? "Active" : "InActive" %>'></asp:Label>
<asp:Label ID="Label1" runat="server" Text='<%# Convert.ToString(Eval("STATUS")) == "Y" ? "Active" : "InActive" %>'></asp:Label>