Solved

<asp:HyperLink not evaluating the column in DataGridView

Posted on 2006-11-07
8
657 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
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 

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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Import csv files to MS SQL 5 81
Change visitor's REMOTE_ADDR to server's REMOTE_ADDR 2 30
IP API - need data... 4 23
Time Conversions...both ways 2 14
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 information …
I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

786 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