Home All Groups Group Topic Archive Search About

Referring to a field name in a hyperlink

Author
24 Sep 2006 1:47 PM
John Meyer
Okay, this might be dumb, but how do I do this?  I knew how to do this
in classic ASP, i.e

<a href="http://www.somelink.com/somepage.asp?id=<%rs("SOMEFIELD_ID")%>"

But how do I do that, considering I have a sql datasource?

Author
24 Sep 2006 2:06 PM
Gaurav Vaish (www.EduJiniOnline.com)
> Okay, this might be dumb, but how do I do this?  I knew how to do this in
> classic ASP, i.e
>
> <a href="http://www.somelink.com/somepage.asp?id=<%rs("SOMEFIELD_ID")%>"
>
> But how do I do that, considering I have a sql datasource?

Where are you using it? Within a DataList / ListView etc?

Few errors in your code:

1. <% must be replaced by <%# if you are using within data bound control.
2. Don't use double quotes at both the places. I'd recommend using single
quote for href.
    <a href='somepage.aspx?id=<%# ... %>' ...

For a data bound control (like GridView or DetailsView), I'd suggest using
HyperLink control as compared to lame anchor element:

<asp:HyperLink NavigateUrl='somepage.aspx?id=<%# DataBinder.Eval(....) %>'
....