I have been creating an order status ASPX page that shows the Date, Carrier, Customer and Tracking Number. The data on this page is generated by a search form where the user can search either via the date or the customer’s name. In our SQL Database, for Tracking Number, it only contains the numerical number such as “759102160484401” (Random FedEx Tracking Number). Whenever a search is pulled up I wanted to hyperlink these to the proper tracking papers respectively to each Shipping company. The current output is as follows:
10/8/2012 — FEDEX — JAMES FRANCO — 759102160484401
Now The Problem. We have the current DataNavigateUrlFormatString set to a FedEx url. We would like this to alternate to the UPS link when it detects that the SQL field for Carrier says “UPS”. How would I accomplish this? Below is the current line for the Tracking number column for the Tracking.aspx file.
<asp:HyperLinkField DataTextField="TRACKNUM" DataNavigateUrlFields="TRACKNUM" HeaderText="Tracking#" Target="_blank" Text="Tracking#"
DataNavigateUrlFormatString="http://www.fedex.com/Tracking?clienttype=dotcom&ascend_header=1&cntry_code=us&language=english&mi=n&tracknumbers={0}"
HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Center" />
Hope this is detailed and much appreciated!
In outline form,
Register an event on OnRowDataBound (Same concept for other databinding controls)
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.onrowdatabound.aspx
Extract from the row the HyperLinkField. Usually using FindControl on the .Row property of the event, or sometimes .Row[x] where x is the index of the cell that holds your control.
Set the DataNavigateUrlFormatString to one string or another depending on what ever lets you know if you need a fedex or ups url.