Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

NavigateUrl syntax passing variable from GridView field to html

Status
Not open for further replies.

DeeMark

Programmer
Feb 10, 2005
15
GB
Would be grateful if any help with syntax trying to pass a variable price value to a shopping cart check out where the price value is a variable based on distance.

All fine when using a fixed integer, problem when trying to name the price value from the Gridview.

Code:
NavigateUrl="[URL unfurl="true"]http://someplace.com/cf/add.cfm?userid=xxxxxxxx&amp;product=someproduct;price='<%#DataBinder.Eval(Container.DataItem,'DistanceFromAddress')%>'&amp;units=1&amp;return=www.ephysioassociates/Default.aspx">HyperLink</asp:HyperLink>[/URL]

Any help appreciated.
 
jbenson
Tks for your prompt response

When price = any numeric (no problem)

When price= reference to the GridView control value then
value always zero.

Have been assuming the syntax was wrong somewhere.
Have 'googled' to no avail.

Have ascertained that value exists on the page behind codepage with Response.Write("DistanceFromAddress") which is OK just cannot get the hyperlink correct?

 
I think it has something to do with the quotes. I don't believe you need the quotes around the container.dataitem code, i.e.
price = '<databinder ....>'

However, I don't like mixing code in markup, it reminds me of the old classic ASP code.

My suggestion would be to build the URL in the code behind and attach that to the hyperlink.
 
Thank you - all noted.

Agree with your suggestion and comment re ASP - will try in code behind although a little confused on should I use form values or hyprlink.
Had previously tried

Code:
<asp:LinkButton ID="LinkButton2" runat="server" 
                    PostBackUrl='<%# String.Format("[URL unfurl="true"]http://ww4.aitsafe.com/cf/add.cfm?userid=xxxxxxxx&amp;product=Appointment%20Booking&amp;price={0}&amp;units=1&amp;return=www.ephysioassociates/default.aspx",[/URL] price)%>'>Booking</asp:LinkButton>
To no avail

Whilst not an expert by any any means - I have not come across a shopping cart accepting a 'varying' price variable in ASP.Net or other language. Cannot believe it is unusual?
 
I have not come across a shopping cart accepting a 'varying' price variable in ASP.Net or other language. Cannot believe it is unusual?
This is not an issue with ASP.NET or the language you are using, it is a syntax issue.
What you should do is use the RowDataBound event of the grid view.
Code:
 Dim dataitem As DataRowView = DirectCast(e.Row.DataItem, DataRowView)

'Make sure you are on a datarow, not the header or footer.
        Select Case e.Row.RowType
            Case DataControlRowType.DataRow
                 DirectCast(e.Row.FindControl("YourHyperLinkNameHere"), HyperLink).NavigateURL = "[URL unfurl="true"]http://someplace.com/cf/add.cfm?userid=xxxxxxxx&product=someproduct&"[/URL] + dataitem("DistanceFromAddress")+ .. the rest of the string you need to generate ...

        End Select
End Sub
 
Thank you very much for the further guidance. Much appreciated. Will try accordingly.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top