Solved

Changing Navigate URL on a GridView

Posted on 2006-11-30
8
780 Views
Last Modified: 2011-10-03
I have a GridView that uses the datanavigateurlformatstring of a HyperLinkField.

The grid displays a list of shipments, mostly USPS, but some UPS and FedEx. This works great for one hyperlink, but of course I need to change it for each row based on a value of the row.

Any creative ideas on how to do this?

Thanks
Randy

HyperLink Field

                        <asp:HyperLinkField DataTextField="tracking_number"
                            datatextformatstring="{0:c}"
                            datanavigateurlfields="tracking_number"
                            datanavigateurlformatstring="http://trkcnfrm1.smi.usps.com/PTSInternetWeb/InterLabelInquiry.do?CAMEFROM=OK&strOrigTrackNum={0}"  
                            HeaderText="Tracking#" SortExpression="shipments.tracking_number"
                            Target="USPSTrackingNumberLookup"
                        />
0
Comment
Question by:randymiller
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 20

Expert Comment

by:brwwiggins
ID: 18049401
Create a template field and then call a function to set the navigate url field based on the field value you want.
0
 

Author Comment

by:randymiller
ID: 18050040
Are you talking about adding something to the GridView RowCreated Event?

Randy
0
 
LVL 4

Expert Comment

by:satish_nagdev
ID: 18050947
hi randy,
is there any field by which you categorize your tracking number to be FedEx, UPS etc? & is it visible column in gridview?

regards,
satish.
0
Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

 
LVL 4

Expert Comment

by:satish_nagdev
ID: 18050956
if you dont want to work on rowcreated/rowdatabound event, other option i could think of is add a simple page with no controls, in gridview redirect to that page with appropriate parameters then in page load of that page server.transfer or respose.redirect to appropriate page.

hope that helps,

regards,
satish.
0
 
LVL 20

Accepted Solution

by:
brwwiggins earned 500 total points
ID: 18051552
building on what satish said, you need a way to identify if it is UPS, FedEX, etc etc.

Then you can add a template field, drag a hyperlink control into the item template and modify the databinding settings. Then create a custom data binding expression like

FormatLink(Eval("tracking_number"))

Then create a function called FormatLink and you can code your logic

here are some examples hinting at what I'm talking about

http://www.asp.net/learn/dataaccess/tutorial12cs.aspx?tabid=63
http://static.asp.net/asp.net/files/DataTutorials/datatutorial11cs.pdf
0
 
LVL 6

Expert Comment

by:manicsquirrel
ID: 18051832
I don't see why what you have doesn't work.  This part, "={0}", should be the value of the "tracking_number" field for that row.  However, below is what I use.  I usually have the href attribute usually looks more like, "href='javascript:void' onClick='cmdTrack({0});'" and I would have a javascript function open a new window or load an iframe and wait for feedback.

Anyway, try this:

<asp:BoundField
   DataField="tracking_number"
   DataFormatString="<a href='http://trkcnfrm1.smi.usps.com/PTSInternetWeb/InterLabelInquiry.do?CAMEFROM=OK&strOrigTrackNum={0}'>{0:c}</a>"
   HeaderText="Tracking#"
   SortExpression="shipments.tracking_number"
   Target="USPSTrackingNumberLookup"
 />
0
 

Author Comment

by:randymiller
ID: 18069272
brwwigins,

I wan't able to get a function to work.

I have gotten it taken care of with the RowDataBound event.

I have always found the order of the events confusing as well as the arguments passed. Have you seen a good tutorial that shows the order of the GridView Events and their usage? I have seen a lot of ones that list them alphabitically, but none that show them in run order.

Thanks
0
 
LVL 20

Expert Comment

by:brwwiggins
ID: 18070103
I haven't found a real good tutorial on it yet either. I struggle with the order of events sometimes as well.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Calculating percentage 2 48
asp.net repeater 2 35
e commerce steps shown instead of self testing 2 56
How do you think this website does searches? 5 34
Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

732 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question