这是我的代码:
<asp:TemplateField HeaderText="App/Deny">
<ItemTemplate>
<asp:Label ID="lblAppDeny" runat="server" Text='<%#Eval("App/Deny").ToString() == "" ? "Paddings" : null + "," + Eval("App/Deny").ToString() == "Approve" ? null : "Approve" + "," + Eval("App/Deny").ToString() == "Deny" ? null : "Deny" %>' CssClass='<%#Eval("App/Deny").ToString() == "" ? "badge warning text-sm" : null + "," + Eval("App/Deny").ToString() == "Approve" ? "badge success text-sm" : null + "," +Eval("App/Deny").ToString() == "Deny" ? null : "badge danger text-sm" %>'>
</asp:Label>
</ItemTemplate>
</asp:TemplateField>
如果String.Empty可用,那么我需要在列中显示三种类型的值,然后该值显示为Pending,如果值是Approve或Deny,则显示该类型。
答案 0 :(得分:0)
您只需在GridView所在的页面上创建一个方法即可处理if else代码。
public string formatValue(string input)
{
if (string.IsNullOrEmpty(input))
{
return "Empty";
}
else if (input == "Pending")
{
return "Is pending";
}
else
{
return "Available";
}
}
在GridView中
<asp:TemplateField HeaderText="App/Deny">
<ItemTemplate>
<%# formatValue(Eval("App/Deny").ToString()) %>
</ItemTemplate>
</asp:TemplateField>