Click here to Skip to main content
13,052,900 members (77,685 online)
Rate this:
Please Sign up or sign in to vote.

I have a user control which has code for repeater. I am using this control in other page. In the user control code behind I am using LING to SQL to get the data from database. In the repeater, I need to display a link for a specific key value. So, I need added an If statement in the .ascx page. Here is the IF condition code I am using,

<% if (%> <%#(string)DataBinder.Eval(Container.DataItem, "key")%>= "50")
<a id="A1" href="" target="_blank">test link</a>
<a id="A2"></a>

But it is showing error in this statement.

I have goggled and also tried this:

<% if ((%> <%#(string)DataBinder.Eval(Container.DataItem, "key")%> <%).equals("50")) {
<a id="testmore" href="" target="_blank" runat="server" >test link</a>
} %>

and this way:
<a id="testmore" href="" target="_blank"  runat="server" 
visible="<%if%>(<%#(string)DataBinder.Eval(Container.DataItem, "key")%><%= "50") ? true : false%>">test link 

But, none of this format are working correctly.

Can any one give me the correct format to write this statement. Please let me know if you need any more information.

Thanks in Advance.

Posted 13-Dec-12 6:46am
Updated 13-Dec-12 7:08am
Sheikh Muhammad Haris 13-Dec-12 14:31pm
Can you specify the error you are getting ?
scorpion_dev 13-Dec-12 15:05pm
For the first format I am getting an error:

Invalid expression term 'else' and highlights <%}else{%>

Second format: CS1525: Invalid expression term ')' and highlights the line:

<% if ((%> <%#(string)DataBinder.Eval(Container.DataItem, "key")%> <%).equals("50")) {

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Save your string "key" value in a publicly declared variable in your server side event, then access it in your aspx code.

public string myKey = string.Empty;

then in your aspx code

<![CDATA[<% if (myKey == "50")
<a id="A1" href="" target="_blank">test link</a>
<a id="A2"></a>
scorpion_dev 13-Dec-12 17:47pm
Hi Sheikh,

Thanks for the reply.

As I told earlier, I am using this inline expressions inside a repeater. I am able to get the value in the code behind. But, I am not sure how can we apply this value to a single item inside repeater.

Also, is there any way we can do this completely using inline expressions (not using code behind).


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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170713.1 | Last Updated 13 Dec 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100