2011-09-14 100 views
1

我在ASP.NET網頁中有這樣的代碼,但是當我運行它時出現錯誤。Eval()和表達式代碼

>  Databinding methods such as Eval(), XPath(), and Bind() can only 
> be used in the context of a databound control. 

問題在哪裏?

 <% if (Helpers.GetInt(Eval("Price")) != 0) 
      { %> 
     <input type="button" name="btnSignUp" value="Sign Up - Plimus »" onclick="window.location='<%#Eval("BuyUrl2")%><%= Common.GetUserIdUrl("&","custom_user_id") %>'" />  
     <% } %> 

我得到線錯誤代碼

<%,如果(Helpers.GetInt(EVAL( 「價格」))!= 0)

我完全直放站代碼如下。正如我早說的,除了IF聲明外,此代碼中的所有內容均可正常工作。我想評估PRICE,如果是!=0顯示按鈕的html代碼。

<ItemTemplate> 
    <div class="row"> 
     <div class="col title"> 
      <%#Eval("Title")%> 
     </div> 
     <hr/> 
     <div class="col price"> 
      <%#string.Format("{0} USD/{1} </br> Instant activation", Helpers.GetDecimal(Eval("Price")).ToString("N"), Portal.GetMembershipTypeLabel(Helpers.GetInt(Eval("Credits"))))%> 
     </div> 
     <div class="col"> 
      <input type="button" name="btnSignUp" value="Sign Up - PayPal »" onclick="window.location='<%#Eval("BuyUrl1")%><%= Common.GetUserIdUrl("&","custom_user_id") %>'" /> 
      <br /> 
      <br /> 
      <% if (Helpers.GetInt(Eval("Price")) != 0) 
       { %> 
      <input type="button" name="btnSignUp" value="Sign Up - Plimus »" onclick="window.location='<%= Eval("BuyUrl2")%><%= Common.GetUserIdUrl("&","custom_user_id") %>'" />  
      <% } %> 

     </div> 
     <hr/> 
    </div> 
</ItemTemplate> 
+0

你嘗試:'<%=的eval( 「BuyUrl2」)%>'呢? – Icarus

+0

@Icarus IF線出現異常 – Tomas

+0

Tomas能否顯示完整的aspx文件? –

回答

2

是的,你正試圖在HTML輸入控件中使用Eval,這是不允許的,正如錯誤所述。

當你因爲這些命令(評估和演示 ...)是針對要綁定的數據源施加結合等的DataList,數據網格,的DataRepeater一個數據boundable控制等評估和演示或綁定和同伴通常執行。這樣做對像原始HTML輸入這樣的控件沒有意義,因爲沒有什麼可以綁定。

注意的<%= Common.GetUserIdUrl...您的通話/使用看起來是正確的,並且可以呆在那裏:)

+0

我得到錯誤的,如果(Helpers.GetInt(EVAL(「價格」))!= 0) – Tomas

+0

我使用直放站此代碼,如果我刪除IF線路一切正常。在這種情況下,<%#Eval(「BuyUrl2」)%>和<%= Common.GetUserIdUrl(「&」,「custom_user_id」)%>都是正確的。問題在於IF語句。 – Tomas