我试图根据我的项模板中的数据绑定集合(从LINQ到SQL)中的值来设置表行的样式,但是这不起作用。
这就是我到目前为止所知道的:
<ItemTemplate>
<%
string style = String.Empty;
if ((string)DataBinder.Eval(Quotes.Cu, "Status") == "Rejected")
style = "color:red;";
else if ((string)Eval("Priority") == "Y")
style = "color:green;";
if (style == String.Empty)
Response.Write("<tr>");
else
Response.Write("<tr style=\"" + style + "\"");
%>
<td>
<%# Eval("QuoteID") %>
</td>
<td>
<%# Eval("DateDue", "{0:dd/MM/yyyy}") %>
</td>
<td>
<%# Eval("Company") %>
</td>
<td>
<%# Eval("Estimator") %>
</td>
<td>
<%# Eval("Attachments") %>
</td>
<td>
<%# Eval("Employee") %>
</td>
</tr>
</ItemTemplate>编辑:
抱歉,我没有说得更清楚!问题是,它抛出了一个错误:
Databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a databound control.发布于 2010-04-17 05:26:08
请把这个换掉
<%
string style = String.Empty;
....
%>通过
<%#
string style = String.Empty;
....
%>请注意,我添加了#
https://stackoverflow.com/questions/2655820
复制相似问题