2010-04-16 40 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。