Solved

Using .EVAL()  on navigateurl property in gridview control

Posted on 2010-08-13
14
1,111 Views
Last Modified: 2013-11-26
How would I write the EVAL expression in this block of code so that the "TrackingNum" fields url is generated depending on the "ShipMethod" field. There are 3 different Shipping methods "UPS","USPS" and "FDXSP".
<asp:GridView ID="GridView8" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource2"
                            Width="868px" CellPadding="4" ForeColor="#333333" GridLines="None">
                            <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
                            <Columns>
                                <asp:HyperLinkField HeaderText="Order #" DataTextField="OrderNum" DataNavigateUrlFields="OrderNum"
                                    DataNavigateUrlFormatString="http://marketplaceadvisor.channeladvisor.com/en/order/order_detail.aspx?il=1&fOrderUID={0}"
                                    Target="_blank" />
                                <asp:HyperLinkField HeaderText="Tracking #" DataTextField="TrackingNum" DataNavigateUrlFields="TrackingNum"
                                    DataNavigateUrlFormatString="http://wwwapps.ups.com/WebTracking/track?HTMLVersion=5.0&loc=en_US&trackNums={0}&track.y=10&Requester=TRK_MOD&showMultipiece=N&detailNumber=undefined&WBPM_lid=homepage%2Fct1.html_pnl_trk"
                                    Target="_blank">
                                    <ItemStyle BackColor="#CCCCCC" Font-Size="X-Small" />
                                </asp:HyperLinkField>
                                <asp:BoundField DataField="ShipDate" HeaderText="ShipDate" SortExpression="ShipDate" />
                                <asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" />
                                <asp:BoundField DataField="Cost" HeaderText="Cost" SortExpression="Cost" />
                                <asp:BoundField DataField="City" HeaderText="City" SortExpression="City" />
                                <asp:BoundField DataField="ShipService" HeaderText="ShipService" SortExpression="ShipService" />
                                <asp:BoundField DataField="ShipMethod" HeaderText="ShipMethod" SortExpression="ShipMethod" />
                            </Columns>
                            <EditRowStyle BackColor="#999999" />
                            
                        </asp:GridView>

Open in new window

0
Comment
Question by:frtools
[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
  • 7
  • 6
14 Comments
 
LVL 16

Expert Comment

by:Stephan
ID: 33433886
I think the only way to do this, is creating a "ItemDataBound" event.
0
 
LVL 5

Assisted Solution

by:KiasChaos83
KiasChaos83 earned 250 total points
ID: 33434334
Hmm.. my solution has two steps.

1) In the code behind, add a public function:

public string GetShippingMethodDescription(string method) {
switch (method) {
case "UPS": return "hello"; break;
case "USPS": return "world; break;
case "FDXSP": return "blah"; break;
}
return "";
}

2) add the following to the aspx

<%# GetShippingMethodDescription(EVAL("ShipMethod")) %>

0
 

Author Comment

by:frtools
ID: 33505158
Sorry for the late response (vacation).

KiasChaos83, when I inserted the code there is an error - Databinding expressions are only supported on objects that have a Databinding event. System.Web.UI.WebControls.HyperLinkField does not have a DataBinding event.
0
Application Discovery Service in AWS

In the era of the cloud, customers migrating away from their existing on-premise infrastructure. This requires lots of planning, strategies, and effort to identify their existing resources and determine how best to migrate.  Datacenter migrations happen in four phases -

 
LVL 16

Expert Comment

by:Stephan
ID: 33508044
instead of using an HyperLinkField, you need to create a templatefield with an hyperlink in it, then add the code that KiasChaos83 has submitted.
0
 

Author Comment

by:frtools
ID: 33510891
I added this following code and get a parse error on the hyperlink tag.


 <asp:TemplateField HeaderText = "Tracking #" >
                                <ItemTemplate>
                                    <asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl='<%#  etShippingMethodDescription(EVAL("ShipMethod","TrackingNum")) %>' />
                                </ItemTemplate>
                                </asp:TemplateField>

Open in new window

0
 
LVL 16

Expert Comment

by:Stephan
ID: 33511964

<asp:TemplateField HeaderText = "Tracking #" >
                                <ItemTemplate>
                                    <asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl='<%#  GetShippingMethodDescription(Eval("ShipMethod")) %>' />
                                </ItemTemplate>
                                </asp:TemplateField>

Open in new window

0
 

Author Comment

by:frtools
ID: 33514990
Appreciate all the help.

It kind of works but I need to pass another eval object into my function how would I do that with an '&' or something else. Also the column does not contain a link.
Below is what I would suppose the eval statement would look like but the error says

<asp:TemplateField HeaderText = "Tracking #" >
                                <ItemTemplate>
                                   <asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl='<%#  GetShippingMethodDescription(Eval("ShipMethod") & Eval("TrackingNum")) %>' />
                                </ItemTemplate>
                                </asp:TemplateField>

My function is as follows:

public string GetShippingMethodDescription(object method, object tracknum)
        {
           
            switch (method.ToString()) {
            case "UPS": return "http://wwwapps.ups.com/WebTracking/track?HTMLVersion=5.0&loc=en_US&trackNums="+tracknum.ToString()+"&track.y=10&Requester=TRK_MOD&showMultipiece=N&detailNumber=undefined&WBPM_lid=homepage%2Fct1.html_pnl_trk"; break;
            case "USPS": return "http://trkcnfrm1.smi.usps.com/PTSInternetWeb/InterLabelInquiry.do?CAMEFROM=OK&strOrigTrackNum=" + tracknum.ToString() ; break;
            case "FDXSP": return "";
            break;
            }
            return "";
        }
0
 

Author Comment

by:frtools
ID: 33515024
Sorry you can disregard the EVAL error. It will not display the hyperlink field and I would like it to be the tracking number that I pull from the database.
0
 
LVL 16

Expert Comment

by:Stephan
ID: 33515088
I know why the hyperlink isn't showing, because you did not define the text property of the hyperlink
0
 

Author Comment

by:frtools
ID: 33515171
Alright I do have an EVAL error on this, excuse my confusion.


Operator '&' cannot be applied to operands of type 'object' and 'object'

<asp:TemplateField HeaderText = "Tracking #" >
                                <ItemTemplate>
                                    <asp:HyperLink ID="HyperLink1" runat="server" Text="TrackingNum" Target ="_blank" NavigateUrl='<%#  GetShippingMethodDescription(Eval("ShipMethod") & Eval("TrackingNum")) %>' />
                                </ItemTemplate>
                                </asp:TemplateField>
0
 
LVL 16

Expert Comment

by:Stephan
ID: 33515201
Use , instead of &
0
 

Author Comment

by:frtools
ID: 33515310
Thank you so much that did it. One last question how would I bind the tracking number from the database in the text field.
0
 
LVL 16

Accepted Solution

by:
Stephan earned 250 total points
ID: 33515323
<asp:TemplateField HeaderText = "Tracking #" >
                                <ItemTemplate>
                                    <asp:HyperLink ID="HyperLink1" runat="server" Text='<%# Eval("TrackingNum") %>' Target ="_blank" NavigateUrl='<%#  GetShippingMethodDescription(Eval("ShipMethod"), Eval("TrackingNum")) %>' />
                                </ItemTemplate>
                                </asp:TemplateField>
0
 

Author Comment

by:frtools
ID: 33515372
Thank you so much.
0

Featured Post

Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

Question has a verified solution.

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

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

636 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