Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Using .EVAL()  on navigateurl property in gridview control

Posted on 2010-08-13
14
Medium Priority
?
1,112 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 1000 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
Stack Overflow Podcast - Developer Story

Welcome to the Stack Overflow podcast recorded Thursday July 20 at Stack Overflow Headquearters in NYC. Your hosts today are podcast regulars Jay Hanlon, David Fullerton, and Ilana Yitzhaki, plus the quite irregular Matt Sherman (Stack Overflow Engineering Manager extraordinaire)

 
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 1000 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

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

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…

722 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