We help IT Professionals succeed at work.

Using hyperlink control within a sqldatasource datalist control to pass a querystring value coming from the sqldatasource

derrekdeveloper
derrekdeveloper used Ask the Experts™
on
I am trying to use a hyperlink control within a data list. The problem I have is I do not know the correct syntax to pass the data value coming from the SQLDataSource. Here is my scenario:



I have a SQLDataSource. It is bringing back multiple values including a field called eid which is an int value.  I need to place a hyper within the datalist and go to a page called favorites. I need to pass the eid value coming back from the SQLDataSource to the favorite.aspx page. I did a databind on the hyperlink and I am able to use the hyperlink to go to a page but the databinding appears to be for the text value only. Not to pass the eid 'field' value in QueryString to the favorites.aspx page, which is what I need to do. I tried to add the eid value by using this code, ?eid={0} but it does not work. Here is the code I have so far:

<asp:HyperLink ID="HyperLink1" runat="server" ForeColor="White" Text='<%# Eval("eid") %>' NavigateUrl="~/favorites_addexercise.aspx?eid={0}"></asp:HyperLink>
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Lead Software Engineer
Commented:
If you want to have variables inside your navigate url using {0}, you have to use String.Format() to do this like so:

<asp:HyperLink ID="HyperLink1" runat="server" ForeColor="White" Text='<%# Eval("eid") %>' NavigateUrl='<%# String.Format("~/favorites_addexercise.aspx?eid={0}", Eval("eid")) %>'></asp:HyperLink>