开发者

populate lable control inside a gridview based on inline Conditional statement

开发者 https://www.devze.com 2023-04-11 15:05 出处:网络
开发者_开发技巧I am trying to display a plain text in the column(contains a label) of gridview based ona condition. Here is my erroneous code. Please correct.

开发者_开发技巧I am trying to display a plain text in the column(contains a label) of gridview based on a condition. Here is my erroneous code. Please correct.

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

Thanks in advance.

BB


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

where FormatText could be a method in your code behind:

protected string FormatText(object o)
{
    int value;
    if (int.Parse(o as string, out value) && value == 0)
    {
        return "NEW";
    }
    return "OLD";
}


Try this :

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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号