Solved

<asp:HyperLink not evaluating the column in DataGridView

Posted on 2006-11-07
8
655 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
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
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…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

708 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

13 Experts available now in Live!

Get 1:1 Help Now