1
Answer

How to Pass Eval value to if statement in aspx page?

Raja

Raja

8y
423
1
if (Request.QueryString["SelectValue"].ToString() == "Cache" && Eval("LOADIND").ToString().Trim() == "EF")
{ %>
<a href="../Home/AddMaterialDraft.aspx?Spirid=<%# Eval("ID") %>&project= <%# Eval("NAME") %>">
<img src="../Images/change.png" style="height: 30px; width: 30px" /></a>
<% } %>
Above code is used in my aspx page. first condition value coming from session so no problem is occured but the second condition is value from datatable in if statement.now i run my code below error is occur  :

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

How to fix this.the if statement is inside the repeater. 
Answers (1)
0
Manas Mohapatra

Manas Mohapatra

NA 29.3k 3.3m 8y
Eval() is used to bind to an UI item that is setup to be read-only (eg: a label or a read-only text box). However, you are using as inline coding so you are getting exception.
What is the need of Eval() to check condition. Create a function and pass value to the function so that you won't use Eval() as inline coding.