Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
Hi,
 
I have a user control which has code for asp.net 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="http://www.google.com" target="_blank">test link</a>
<%}else{%>
<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="http://www.google.com" target="_blank" runat="server" >test link</a>
} %>
 
and this way:
<a id="testmore" href="http://www.google.com" 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.
 
Scorpion
Posted 13-Dec-12 6:46am
Edited 13-Dec-12 7:08am
v2
Comments
Sheikh Muhammad Haris at 13-Dec-12 14:31pm
   
Can you specify the error you are getting ?
scorpion_dev at 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
good
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")
   {
%>]]>
  Permalink  
Comments
scorpion_dev at 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).
 
Thanks

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 310
1 CPallini 310
2 George Jonsson 269
3 Gihan Liyanage 255
4 OriginalGriff 245
0 OriginalGriff 4,903
1 CPallini 3,960
2 Sergey Alexandrovich Kryukov 3,474
3 George Jonsson 2,786
4 Gihan Liyanage 2,386


Advertise | Privacy | Mobile
Web02 | 2.8.140905.1 | Last Updated 13 Dec 2012
Copyright © CodeProject, 1999-2014
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