Link to home
Start Free TrialLog in
Avatar of randymiller
randymiller

asked on

Changing Navigate URL on a GridView

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"
                        />
Avatar of brwwiggins
brwwiggins
Flag of United States of America image

Create a template field and then call a function to set the navigate url field based on the field value you want.
Avatar of randymiller
randymiller

ASKER

Are you talking about adding something to the GridView RowCreated Event?

Randy
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.
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.
ASKER CERTIFIED SOLUTION
Avatar of brwwiggins
brwwiggins
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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"
 />
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
I haven't found a real good tutorial on it yet either. I struggle with the order of events sometimes as well.