Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 226 Vote(s) - 3.58 Average
  • 1
  • 2
  • 3
  • 4
  • 5
#Eval if statement in repeater

#1
I'm trying to check a string value inside a repeater, and if it has value then write a link, but can't seem to get it to work. If there is a value in myUrl then I want to display the link.

<%if( %> <%#Eval("myURL").ToString().Length > 0 %>
<a title="myTitle" target="_blank" href="<%# Eval("myURL") %>">my link</a>
<% } %>

Can anyone please help?
Reply

#2
I personally hate using conditional logic like that in the page.

There are two options that I think are better. You could have a Hyperlink control in the repeater - and set the visibility depending on if the myURL param is there.

visibility='<% #Eval("myURL").ToString().Length > 0 %>'

OR what you can do is have a method on your code behind that you call back to with the "myURL" param.

E.g.

public string CreateURL(string myURL){
if(!string.IsNullOrEmpty(myURL)){
return "<a ... ";
}

return string.Empty;
}

And call in ASPX

<%# CreateURL(Eval("myURL").ToString()) %>

NB this is untested code but this is the ways I usually do this sort of thing.


Reply

#3
this will help

[To see links please register here]

[To see links please register here]

[To see links please register here]

Reply

#4
Try adding a `runat="server"` and then add a script block for the (new) server-side visible property:

<a title="myTitle" target="_blank" href="<%# Eval("myURL") %>" runat="server" visible='<%#Eval("myURL").ToString().Length > 0 %>'>my link</a>

Reply

#5
I would use the String.Format and include the HTML as part of the string. Admittedly, it's not the neatest piece of code ever written, but in my opinion it's the best option:

For example the below will output an anchor tag if the property *Url* exists, otherwise it will output a span.

<%# string.Format(Eval("Url") != null ? "<a href=\"{0}\">{1}</a>" : "<span>{1}</span>", Eval("Url"), Eval("Text")) %>">
Reply

#6
You can also call your public function inside code behind file:

<%# MyFunction(Eval("myURL").ToString().Length) %>

Reply

#7
try this code !!!

<%#Eval("myURL").ToString().Length > 0 ?
"<a title='myTitle' target='_blank' href='<%# Eval("myURL") %>'>my link</a>":""%>
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through