[英]How to bind Text in Gridview DataBinder asp.net c#?
我在Gridview中显示我的表值,在状态列的数据库中,我将“活动”和“不活动”的值分别存储为“ Y”和“ N”。 但是在Gridview中显示时,我想将状态显示为“活动”和“非活动”,而不是Y和N。
<asp:Label ID="lblmerstatus" runat="server" Text= '<%# DataBinder.Eval(Container, "DataItem.STATUS") == "Y" ? "Active" : "InActive"%>'></asp:Label>
但是即使状态为Y,它也始终只向我显示InActive。 请帮忙
用这个可能会帮助你
<asp:Label ID="lblmerstatus" runat="server" Text'<%# Convert.ToBoolean(Eval("Status")) %>'
Text='<%# Eval("Status").ToString().Equals("True") ? "Active" : "InActive" %>' />
尝试使用
<asp:Label ID="lblmerstatus" runat="server"
Text= '<%# DataBinder.Eval(Container, "STATUS").ToString() == "Y" ? "Active" : "InActive"%>' ></asp:Label>
现在使用它可能会帮助您...
解决方案1:如果您的表字段“ STATUS”返回布尔值,如true(1)或false(0):
<asp:Label ID="Label1" runat="server" Text='<%# Convert.ToBoolean(Eval("STATUS")) == true ? "Active" : "InActive" %>'></asp:Label>
解决方案2:如果您的表字段“ STATUS”返回字符串值,例如Y或N:
<asp:Label ID="Label1" runat="server" Text='<%# Convert.ToString(Eval("STATUS")) == "Y" ? "Active" : "InActive" %>'></asp:Label>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.