2010-04-16 47 views
0

我试图根据我的项目模板中的数据绑定集合(从LINQ到SQL)中的值设置表格行的样式,但它不起作用。ASP.NET Repeater - 将项目评估为int?

这是我到目前为止有:

<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. 
+1

对不起,这行不工作

<%# string style = String.Empty; .... %> 

通知? – 2010-04-16 20:12:26

回答

1

请把这个

<% 
    string style = String.Empty; 
    .... 
%> 

由我添加#

0

哪部分是int?我不明白int部分是如何应用的?如果对象是一个真正的int,你总是可以将它转换为int(int)Eval(“Value”),或者如果一个字符串,你可以使用int.Parse或int.TryParse进行转换(如果它可能会更安全该字段不是int)。

HTH。