Solved

Using .EVAL()  on navigateurl property in gridview control

Posted on 2010-08-13
14
1,084 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
  • 7
  • 6
14 Comments
 
LVL 16

Expert Comment

by:Stephan
Comment Utility
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
Comment Utility
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
Comment Utility
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
 
LVL 16

Expert Comment

by:Stephan
Comment Utility
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
Comment Utility
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
Comment Utility

<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
Comment Utility
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
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 

Author Comment

by:frtools
Comment Utility
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
Comment Utility
I know why the hyperlink isn't showing, because you did not define the text property of the hyperlink
0
 

Author Comment

by:frtools
Comment Utility
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
Comment Utility
Use , instead of &
0
 

Author Comment

by:frtools
Comment Utility
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
Comment Utility
<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
Comment Utility
Thank you so much.
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

772 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now