1

我正在尝试根据条件在 gridview 的列(包含标签)中显示纯文本。这是我的错误代码。请纠正。

 <asp:Label ID="lblAsgn" runat="server"   Text= '<%#Eval("StatusId") == 0 ? "NEW" : "OLD" %>' > </asp:Label>

提前致谢。

BB

4

2 回答 2

3
<asp:Label 
    ID="lblAsgn" 
    runat="server"   
    Text='<%# FormatText(Eval("StatusId")) %>' />

whereFormatText可能是您代码中的方法:

protected string FormatText(object o)
{
    int value;
    if (int.Parse(o as string, out value) && value == 0)
    {
        return "NEW";
    }
    return "OLD";
}
于 2011-10-05T21:54:35.057 回答
1

尝试这个 :

 <asp:Label ID="lblAsgn" runat="server"   Text= '<%# Eval("StatusId").Equals(0) ? "NEW" : "OLD" %>' > </asp:Label>
于 2011-10-05T21:57:52.720 回答