Click here to Skip to main content
16,007,443 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to execute if statement in Repeater itemtemplate like below

C#
<Repeater>
   <Itemtemplate>
      <% if(DataBinder.Eval(Container.DataItem, "item").ToString() == "something") { %>

      <% } %>
   <Itemtemplate>
</Repeater>


the code above is wrong, because the DataBinder.Eval(Container.DataItem, "item") can't be nested in <% %>, I want to know how can I use Eval items in <% %> block.
Posted

Read this article about different server tags for including different content - http://weblogs.asp.net/ahmedmoosa/embedded-code-and-inline-server-tags[^]
You problem is that you use <% %> with if (which is good) and with Eval (which is not good). If you have to do it this way (and not using server side events) you have to use some other form of retrieving the value from the data than Eval...
Something like DataTabe.Rows[0]["column"]...
 
Share this answer
 
You'll want to use one of the events instead of trying to do it in ASPX. For example, you could use the ItemDataBound event:

http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.repeater(v=vs.110).aspx[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900