2011-09-14 123 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