How to add a querystring to a databound hyperlink?

G

Guest

Hi,

I have a page which displays a list of items retrieved from a database as
hyperlinks and bound using Databinder.Eval. I would now like to set the
navigateURL property to be a page plus a querystring containing an id, but
when I try to do this is always gives me errors regarding the attribute not
being well formed.

The code I have in place is:

<asp:HyperLink ID="hlQuestion" runat="server" Text='<%# DataBinder.Eval
(Container.DataItem, "QuestionTitle") %></asp:HyperLink>

I have tried adding theNavigateURL like this:

<asp:HyperLink ID="hlQuestion" runat="server"
NavigateUrl="~/displayreplies.aspx?qid=" + '<%# DataBinder.Eval
(Container.DataItem, "QuestionID") %>'
Text='<%# DataBinder.Eval (Container.DataItem, "QuestionTitle") %>'>
</asp:HyperLink>

but it doesn't like it. I have tried other combinations but nothing seems
to work.

Can anyone show me how it should be done?
 
G

Guest

Hi,

I have a page which displays a list of items retrieved from a database as
hyperlinks and bound using Databinder.Eval. I would now like to set the
navigateURL property to be a page plus a querystring containing an id, but
when I try to do this is always gives me errors regarding the attribute not
being well formed.

The code I have in place is:

<asp:HyperLink ID="hlQuestion" runat="server" Text='<%# DataBinder.Eval
(Container.DataItem, "QuestionTitle") %></asp:HyperLink>

I have tried adding theNavigateURL like this:

<asp:HyperLink ID="hlQuestion" runat="server"
NavigateUrl="~/displayreplies.aspx?qid=" + '<%# DataBinder.Eval
(Container.DataItem, "QuestionID") %>'
Text='<%# DataBinder.Eval (Container.DataItem, "QuestionTitle") %>'>
</asp:HyperLink>

but it doesn't like it. I have tried other combinations but nothing seems
to work.

Can anyone show me how it should be done?

Try this

NavigateUrl="<%# '~/displayreplies.aspx?qid=' + DataBinder.Eval
(Container.DataItem, 'QuestionID') %>"
 
G

Guest

Thanks Alexey, but that didn't do it. Got an error saying Too many
characters in literal.

I'll keep looking, I guess....
 
G

Guest

Thanks Alexey, but that didn't do it. Got an error saying Too many
characters in literal.

ah, okay... it means you need to replace ( " ) by ( ' ) and ( ' ) by
( " )

NavigateUrl='<%# "~/displayreplies.aspx?qid=" + DataBinder.Eval
(Container.DataItem, "QuestionID") %>'
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,073
Latest member
DarinCeden

Latest Threads

Top