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

Forum statistics

Threads
473,995
Messages
2,570,226
Members
46,815
Latest member
treekmostly22

Latest Threads

Top