Skip to main content

How to use DataBinder.Eval in HyperLink NavigationUrl - ASP.net

I wanted to append page Url with DataBinder.Eval value in ASP.NET hyperlink control on ASP.NET HTML source. I was trying it using many ways and also search for resources on web but I could not find any useful thing.

I thought this will help u guys to get an idea about appending two strings. Solution as follows.

<asp:HyperLink ID="customerHyperLink" runat="server"
Text= '<%# DataBinder.Eval(Container.DataItem, "Name") %>' NavigateUrl='<%# "~/Pages/YourPage.aspx?id=" + DataBinder.Eval(Container.DataItem, "id") %>'></asp:HyperLink>

You can see how I have appended these two value in NavigateUrl property.

Hope some one will get the advantage of this post.

Comments

Anonymous said…
I kept getting "Input string was not in a correct format" when I used your exact code. So I changed the '+' in the navigateurl to a '&' and it works. I have used '+' before to concatenate but for some reason it would not take it here... I guess it's just another option. Thanks for the tip!
Oshadha said…
Thanks for the aditional info Anthony.

Popular posts from this blog

Common Design Principles

There are number of common design principles that, like design patterns, best practice over the years to build maintainable software. I'm up to describe some widely used design principles though out the post. Following common principle are extracted by the same book that I mentioned before ( Professional ASP.Net Design Patterns - Scott Millet ). Principles are as follows: Keep It Simple Stupid (KISS) One common issue in software programming is over-complicating a solution. So main concern of this principle is keep the code simple but not simplistic. Eventually this will avoid unnecessary complexities. Don't Repeat yourself (DRY) Main concern of this principle is to avoid the repetition. In other words this is all about abstracting out the common functionalities into a single place. Ex: If there is a price calculation method in a system. It should lay in a single place there. Tell Don't Ask The Tell, Don’t Ask principle is closely aligned with encapsulation and the assignin...

LINQ : Query expression vs Lambda Expression

All the time I was using LINQ on projects I was wondering whether there is a performance difference between query expression and lambda expression. So I decided to dig into it. I wanted to examine MSIL for both of these situations. I wrote small class which has two methods. One is using query expression and the other one is using lambda. I complied this code and got the dll and view the MSIL using ildasm.exe. This following picture will show you the MSIL of GetFirst() method. And this following picture will show you the MSIL of the GetSecond() method. Yes!!! you can see that there is no different between these 2 MSIL. Will there be a performance difference???