C# 在某些条件下显示特定单词评估Asp.net

C# 在某些条件下显示特定单词评估Asp.net,c#,asp.net,gridview,eval,repeater,C#,Asp.net,Gridview,Eval,Repeater,Condition可在某种条件下在网格视图中显示特定单词 像这样的东西可以在Gridview 我收到一个格式不正确的错误服务器标记使用以下代码: <asp:Label ID="lblLeaveStatus" runat="server" Font-Bold="true" Text='<%# Eval("Leave_Status").ToString() == 'A' ? 'Approved' : 'Applied' %>'></asp:Label> 使用以

Condition可在某种条件下在
网格视图中显示特定单词

像这样的东西可以在
Gridview

我收到一个格式不正确的错误服务器标记

使用以下代码:

<asp:Label ID="lblLeaveStatus" runat="server" Font-Bold="true" Text='<%# Eval("Leave_Status").ToString() == 'A' ? 'Approved' : 'Applied' %>'></asp:Label>

使用以下代码:

<asp:Label ID="lblLeaveStatus" runat="server" Font-Bold="true" Text='<%# Eval("Leave_Status").ToString() == 'A' ? 'Approved' : 'Applied' %>'></asp:Label>

试试这个

<% if(Eval("Leave_Status").ToString() == "A"{%>

<asp:Label ID="lblLeaveStatus" runat="server" Font-Bold="true" Text="Approved"></asp:Label>

<%}
else {
%>
<asp:Label ID="lblLeaveStatus" runat="server" Font-Bold="true" Text="Applied"></asp:Label>

<%}%>

试试这个

<% if(Eval("Leave_Status").ToString() == "A"{%>

<asp:Label ID="lblLeaveStatus" runat="server" Font-Bold="true" Text="Approved"></asp:Label>

<%}
else {
%>
<asp:Label ID="lblLeaveStatus" runat="server" Font-Bold="true" Text="Applied"></asp:Label>

<%}%>


Chaange to-1问题在于OP在服务器代码标记内的三元运算符字符串值上有错误的引号(单引号),因此必须使用双引号。否则他的代码就没问题了。按照这个答案所建议的重写让我想起了经典的ASP,而不是ASP.net.Chaange to-1。问题是OP在服务器代码标记内的三元运算符字符串值上有错误的引号(单引号),因此必须使用双引号。否则他的代码就没问题了。正如这个答案所暗示的,重写让我想起了经典的ASP,而不是ASP.net。