?
Solved

<asp:HyperLink not evaluating the column in DataGridView

Posted on 2006-11-07
8
Medium Priority
?
664 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
[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
  • 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
Industry Leaders: 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!

 

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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:   The Exchange of informatio…
Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

752 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