【问题标题】:How to bind Text in Gridview DataBinder asp.net c#?如何在 Gridview DataBinder asp.net c# 中绑定文本?
【发布时间】:2014-07-03 08:52:28
【问题描述】:

我在 Gridview 中显示我的表值,在状态列的数据库中,我将值分别存储为“活动”和“非活动”的“Y”和“N”。但是在 Gridview 中显示时,我想将状态显示为 Active 和 InActive 而不是 Y 和 N。

 <asp:Label ID="lblmerstatus" runat="server" Text= '<%# DataBinder.Eval(Container, "DataItem.STATUS") == "Y" ? "Active" : "InActive"%>'></asp:Label>

但即使状态为 Y ,它也总是只向我显示 InActive 。请帮忙

【问题讨论】:

    标签: c# asp.net gridview data-binding


    【解决方案1】:

    使用这个可能会对你有所帮助

    <asp:Label ID="lblmerstatus" runat="server" Text'<%# Convert.ToBoolean(Eval("Status")) %>'
      Text='<%# Eval("Status").ToString().Equals("True") ? "Active" : "InActive" %>' />
    

    【讨论】:

      【解决方案2】:

      现在使用它可能会对您有所帮助...

      解决方案 1:如果您的表字段“状态”返回布尔值,如 true(1) 或 false(0):

      <asp:Label ID="Label1" runat="server" Text='<%# Convert.ToBoolean(Eval("STATUS")) == true ? "Active" : "InActive" %>'></asp:Label>
      

      解决方案 2:如果您的表字段“状态”返回字符串值,如 Y 或 N:

      <asp:Label ID="Label1" runat="server" Text='<%# Convert.ToString(Eval("STATUS")) == "Y" ? "Active" : "InActive" %>'></asp:Label>
      

      【讨论】:

        【解决方案3】:

        尝试使用

        <asp:Label ID="lblmerstatus" runat="server"
        Text= '<%# DataBinder.Eval(Container, "STATUS").ToString() == "Y" ? "Active" : "InActive"%>' ></asp:Label>
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2014-09-09
          • 2013-10-29
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2020-06-11
          • 1970-01-01
          相关资源
          最近更新 更多