I'm trying to style a table row based upon a value in the databound collection (from LINQ to SQL) in my item template, however it's not working.
This is what I have so far:
<ItemTemplate>
<%
string style = String.Empty;
if ((string)DataBinder.Eval(Quotes.Cu, "S开发者_如何转开发tatus") == "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>
EDIT:
Sorry I didn't make this clearer! The problem is, It's throwing an error:
Databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a databound control.
Please change this
<%
string style = String.Empty;
....
%>
by
<%#
string style = String.Empty;
....
%>
Notice that I added #
Which part is the int? I don't see how the int part applies? If the object is truly an int, you can always cast it to int as (int)Eval("Value"), or if a string, you can convert using int.Parse or int.TryParse (this is safer if its possible for the field to not be an int).
HTH.
精彩评论