how to implement this?

  • Thread starter Thread starter soni2926
  • Start date Start date
S

soni2926

hi,
I have a repeater on a page that's going to build out music content,
images and links to cds. Some of these cds do not have links, and
some do, the ones with links i'm going to have to open in a new page,
so my links are going to look like:
<a href="<%# Eval("linkhere") %> target="_blank">Link</a>
something like that, now the problem is how do i build that for cds
with no links, so they don't open up blank pages, maybe just have it
so there is no link for them all together. is it better for me to
just add another column to the datatable i'm getting back, that has
_blank or nothing for the target attribute, or something else better?
any suggestions?

thanks.
 
You can expose a public method on the code behind to handle this mini logic
situations.



Here is a crappy example.



This is a method on the CODE BEHIND page.


protected string DetermineSearchForLastNameURL(object
EmployeeLastName)
{
//yes the "object" in the argument is on purpose

string empLastName = EmployeeLastName.ToString();

if(empLastName.Length>0)
{

return
string.Format("http://www.google.com/search?source=ig&hl=en&rlz=&q={0}",
HttpUtility.UrlEncode(empLastName));
}

return "#";


}



Then..on the repeater (aspx code)

<a href='<%# DetermineSearchForLastNameURL(DataBinder.Eval(Container,
"DataItem.LastName") )%>'>HERE</a>

You can do the same for the target if you want.

That's one way...there are others.




But that is a great trick for mini rules like that.

The above (should) create a link like this for a data bind for "Smith"

<a href='http://www.google.com/search?source=ig&hl=en&rlz=&q=Smith'>HERE</a>

and

<a href='#'>HERE</a>
for people who don't have a last name (ha ha)....Its just an example !!
 
Back
Top