Solved

<asp:HyperLink not evaluating the column in DataGridView

Posted on 2006-11-07
8
656 Views
Last Modified: 2008-01-16
Hi,

I have the following inside of a DataGridView:

                        <asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl="DealEntry.aspx?TradeId='<%#Eval('TradeId')%>'"
                            Text='Select'></asp:HyperLink>


When it passes it to the DealEntry it does not evaluate it.  Instead I get the following URL:

http://localhost/Test/DealEntry.aspx?TradeId='<%#Eval('TradeId')%>'

Thanks
0
Comment
Question by:techhound
  • 4
  • 4
8 Comments
 
LVL 58

Expert Comment

by:amit_g
ID: 17891042
Like this ...

<asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl='DealEntry.aspx?TradeId=<%#Eval("TradeId")%>' Text='Select'></asp:HyperLink>
0
 

Author Comment

by:techhound
ID: 17891123
Thanks for the information.

I copied your example directly into my code and it did not work.  It gives this as the URL:

http://localhost/Test/DealEntry.aspx?TradeId=<%#Eval("TradeId")%>

It doesn't seem to evaluate the column.

Thanks
0
 
LVL 58

Expert Comment

by:amit_g
ID: 17891194
Is everything else in the datagrid bound? Could you please show us the whole DataGrid tag. Also what version of .Net are you using? This would work in 2.0 only. For 1.0 and 1.1 you have to use Databinder.Eval(Container.DataItem, "TradedId")
0
 

Author Comment

by:techhound
ID: 17891301
Hi, I am using .NET 2.0

Here is the Grid:

               <asp:GridView ID="GridView1" runat="server" AllowPaging="True"
            AutoGenerateColumns="False" CssClass="MasterGrid" DataSourceID="SqlDataSource1" Width="850px" BorderStyle="None" CellPadding="3" GridLines="Vertical" BackColor="White" BorderColor="#999999" BorderWidth="1px" HorizontalAlign="Left" OnRowCommand="GridView1_RowCommand">
            <FooterStyle CssClass="FooterStyle" ForeColor="Black" BackColor="#CCCCCC" />
            <RowStyle CssClass="RowStyle" Font-Names="Tahoma" Font-Size="9pt" BackColor="#EEEEEE" ForeColor="Black" />
            <EditRowStyle CssClass="RowFormat" />
            <PagerStyle CssClass="PagerStyle" Font-Names="Century" Font-Size="10pt" BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" />
            <SelectedRowStyle BackColor="#008A8C" Font-Bold="True" ForeColor="White" />
            <HeaderStyle BackColor="#000084" Font-Bold="True" ForeColor="White" HorizontalAlign="Center" />
            <AlternatingRowStyle BackColor="Gainsboro" />
            <Columns>
                <asp:TemplateField>
                    <ItemTemplate>
                    <asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl='DealEntry.aspx?TradeId=<%#Eval("TradeId")%>' Text='Select'></asp:HyperLink>                    </ItemTemplate>
                </asp:TemplateField>
                <asp:BoundField DataField="TradeId" HeaderText="Trade Id" InsertVisible="False" SortExpression="TradeId" />
                <asp:BoundField DataField="CreditSpread" HeaderText="Credit Spread" SortExpression="CreditSpread" />
                <asp:BoundField DataField="Protection" HeaderText="Protection" SortExpression="Protection" />
                <asp:BoundField DataField="TradeDate" HeaderText="Trade Date" SortExpression="TradeDate" />
                <asp:TemplateField HeaderText="CounterPartyId" SortExpression="CounterPartyId">
                    <EditItemTemplate>
                        <asp:DropDownList ID="DropDownList2" runat="server" DataSourceID="CounterPartyDataSource"
                            DataTextField="counterParty" DataValueField="id">
                        </asp:DropDownList><asp:SqlDataSource ID="CounterPartyDataSource" runat="server"
                            ConnectionString="<%$ ConnectionStrings:WarehouseConnectionString1 %>" SelectCommand="SELECT [id], [counterParty] FROM [CounterParties]">
                        </asp:SqlDataSource>
                    </EditItemTemplate>
                    <ItemTemplate>
                        <asp:Label ID="Label1" runat="server" Text='<%# Bind("CounterPartyId") %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:BoundField DataField="TradeNotional" HeaderText="TradeNotional" SortExpression="TradeNotional" />
            </Columns>
            <EmptyDataTemplate>
                Please Select Reference Entity!
            </EmptyDataTemplate>
        </asp:GridView>
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 58

Expert Comment

by:amit_g
ID: 17891487
To debug change

                <asp:TemplateField>
                    <ItemTemplate>
                                        <asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl='DealEntry.aspx?TradeId=<%#Eval("TradeId")%>' Text='Select'></asp:HyperLink>
                    </ItemTemplate>
                </asp:TemplateField>

to

                <asp:TemplateField>
                    <ItemTemplate>
                            TradeId : <%# Eval("TradeId") %><br>
                            <asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl='DealEntry.aspx?TradeId=<%#Eval("TradeId")%>' Text='Select'></asp:HyperLink>                    
                    </ItemTemplate>
                </asp:TemplateField>

What do you get? How many rows do you get?
0
 

Author Comment

by:techhound
ID: 17891549
Hi,

When I do that I get the proper Trade Id. It doesn't seem to evaluate it correctly in the Hyperlink though.  Very strange!
0
 
LVL 58

Accepted Solution

by:
amit_g earned 500 total points
ID: 17892336
Do it like this ...

<asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl='<%# "DealEntry.aspx?TradeId=" & Eval("TradeId") %>' Text='Select'></asp:HyperLink>

If you are using C# use + instead of &.
0
 

Author Comment

by:techhound
ID: 17892372
So Cool! That Worked! Awesome and Many Thanks!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Leverage browser caching 2 55
migrate from classic ASP to C# .NET 5 69
Need help editing script 3 65
Why Bundles is not working on certain files - ASP MVC 3 44
I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…

912 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

21 Experts available now in Live!

Get 1:1 Help Now