Geeks With Blogs

Bunch's Blog One day I'll have a catchy subtitle, one day

Here is how you can add a database value to the URL of a HyperLink that is in a GridView. In this example the text displayed is the same as the value added to the URL. Also the data is bound through a SqlDataSource and the “ID” value is from the output of the Select statement the SqlDataSource uses. This is a quick way to put the data in the URL without using any code in the code behind.

<asp:TemplateField HeaderText="ID" >

   <ItemTemplate>

<asp:HyperLink ID="hlID" runat="server" Text='<%# EVAL("ID") %>'                NavigateUrl='<%#"Default.aspx?ID=" + EVAL("ID") %>'/>

   </ItemTemplate>

</asp:TemplateField>

Technorati Tags: ,
Posted on Wednesday, July 30, 2008 2:45 PM ASP.Net | Back to top


Comments on this post: NavigateUrl and EVAL

# re: NavigateUrl and EVAL
Requesting Gravatar...
i was looking everywhere for an example that WORKS

thanks!!!
Left by sudhir on Nov 05, 2008 6:28 AM

# re: NavigateUrl and EVAL
Requesting Gravatar...
Thank you!
This issue has taken me all day.
The cheque is in the post ;)
Left by Billy on Jan 28, 2009 9:56 AM

# re: NavigateUrl and EVAL
Requesting Gravatar...
Awesome! Thanks.
Left by Brownie on Feb 10, 2009 10:41 AM

# re: NavigateUrl and EVAL
Requesting Gravatar...
Thankyou so much
Left by aspci on Mar 22, 2009 10:36 PM

# re : Navigate Url
Requesting Gravatar...
its very useful code
Left by ewitttas on Jan 19, 2010 1:32 AM

# re: NavigateUrl and EVAL
Requesting Gravatar...
Can anyone explain why I encountered an error...
I used the code as shown and it said there was an input error and the string wasn't properly formed. I changed the '+' to an '&' and it works fine and correctly.

Chris

P.S. Sorry the topics a bit old, very helpful though and just what I needed!
Left by Chris on Apr 12, 2010 7:26 AM

# re: NavigateUrl and EVAL
Requesting Gravatar...
<asp:HyperLink ID="Gebruiker" runat="server" Text="Gebruikernr" NavigateUrl='<%#"About.aspx?usernr"= DataBinder.Eval(Container,"UserID") %>'></asp:HyperLink>

This part of code results in an error telling : The left side of an assignment should be a variable or property. However, I can't find the problem. Only one thing is not that clear to me: the "UserID", is this a name that has to be equal to sth in the database, or where do I get this from??
Left by Kris on Sep 22, 2010 2:21 PM

# re: NavigateUrl and EVAL
Requesting Gravatar...
exactly what I am looking for - thanx alot!
Left by vitellius on Sep 28, 2010 10:53 AM

# re: NavigateUrl and EVAL
Requesting Gravatar...
thanks ;]
Left by s on Nov 14, 2011 9:05 AM

# re: NavigateUrl and EVAL
Requesting Gravatar...
Hi thank you it was working for me
Left by balaji on Dec 19, 2011 12:31 AM

# re: NavigateUrl and EVAL
Requesting Gravatar...
Works great. Thanks.
Left by Chris Doan on Dec 20, 2011 12:04 PM

# re: NavigateUrl and EVAL
Requesting Gravatar...
After '<%# intelliTrace doesn't work. Why? or that's a bug of my VS 2010?
Left by Alfredo on May 04, 2012 4:52 AM

# re: NavigateUrl and EVAL
Requesting Gravatar...
Thanks - loads of examples on the net but none of them worked - this one does!!! thank-you thank-you!!!!
Left by Jason Woolf on May 14, 2012 4:47 PM

# re: NavigateUrl and EVAL
Requesting Gravatar...
Thanks a lot i spend almost a day for this!
Left by Priy on Jun 30, 2012 5:14 PM

# re: NavigateUrl and EVAL
Requesting Gravatar...
doesn't work...
Left by sdfsdfsdf on Aug 10, 2012 5:54 AM

# re: NavigateUrl and EVAL
Requesting Gravatar...
Thanks a lot
Left by sdsdsd on Dec 07, 2012 4:14 AM

# re: NavigateUrl and EVAL
Requesting Gravatar...
NavigateUrl and EVAL not working...the hyperlink becomes non clickable
Left by Shahzad on Feb 10, 2013 9:44 AM

# re: NavigateUrl and EVAL
Requesting Gravatar...
Thanks so much. THIS WORKED :)
Left by adsf on Apr 15, 2013 10:27 AM

# re: NavigateUrl and EVAL
Requesting Gravatar...
Thanks so mush. yeeeeeeyy !! finnaly !!! it works !
Left by loubna on May 15, 2013 7:08 PM

# re: NavigateUrl and EVAL
Requesting Gravatar...
Thankuuuuuu so much ...it works!!!!!!
Left by Mak on May 15, 2014 3:08 AM

Your comment:
 (will show your gravatar)


Copyright © Bunch | Powered by: GeeksWithBlogs.net