Dynamic QueryString!

A

Adam Knight

Hi all,

I am wanting to url the HyperLink server control in a datagrid.
I am trying to append the id field of the datagrid to the end of the
navigate url.
The code below is causing a problem.

<asp:HyperLink ID="lnkArea" NavigateUrl="index.aspx?aid=<%#
Container.DataItem("bsc_assmnt_area_id")%>" Runat="server"><%#
Container.DataItem("name")%></asp:HyperLink>

Can anyone enlighten me and let me know how to fix this?

Cheers,
Adam
 
K

Ken Dopierala Jr.

Hi Adam,

I don't have the code I used to use in front of me. I think I put a
"Public" function in my code behind. Then here:

NavigateUrl="index.aspx?aid=<%# Container.DataItem("bsc_assmnt_area_id")%>"

I did this:

NavigateUrl="<%#
MyPublicFunction(Container.DataItem("bsc_assmnt_area_id"))%>"

Then I would have MyPublicFunction return the whole URL "index.aspx?aid=10".
The function would be of type string and receive the dataitem as a string or
integer. You may have to do a CStr or CInt around the Container.DataItem
function. Another thing this allowed me to do at the time was switch that
URL on the fly which I needed to do depending on the user's security level.
Good luck! Ken.
 
P

Patrice

What is the behavior you see ?

I suspect the problem is that you can't embed such an expression inside a
literal string. Try :

NavigateUrl='<%# "index.aspx?aid=" &
Container.DataItem("bsc_assmnt_area_id")%>'
 
H

Hrvoje Vrbanc

I've seen such databinding reporting "Server tag is not well formed" if
databinding expression <%#....%> was eclosed within double quotes ("<%#....
%>") instead of single ones ('<%#....%>').

Maybe it could help!
Hrvoje
 
P

Patrick.O.Ige

Adam
Ken's solution would be handy and its more flexible but
Patrice's solution too would work since embedding such an expression
inside a literal string won't work
Make sure the NaviageURL looks like this = '<% %>'
with single quotes
Hope that helps
Patrick
 

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,780
Messages
2,569,611
Members
45,278
Latest member
BuzzDefenderpro

Latest Threads

Top