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.