Eval() and expression code
I have such code in ASP.NET web page but when I run it I get error.
开发者_如何学C> Databinding methods such as Eval(), XPath(), and Bind() can only
> be used in the context of a databound control.
Where is the problem?
<% 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") %>'" />
<% } %>
I get error code on line
<% if (Helpers.GetInt(Eval("Price")) != 0)
I complete Repeater code is below. As I said early everything in this code works fine except IF
statement. I want to evaluate PRICE
and if it is !=0
show button html code.
<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>
yes, you are trying to use Eval in an HTML input control, which is not allowed as stated correctly by the error.
Eval or Bind and fellows are executed usually when you bind a data-boundable control like DataList, DataGrid, DataRepeater and so on because these commands (Eval...) are applied against the DataSource you are binding. doing so against a control like raw HTML input has no meaning because there is nothing to bind against.
notice that your call/usage of <%= Common.GetUserIdUrl...
looks correct and can stay there :)
精彩评论