1

我的页面中有这个GridView

    <asp:GridView ID="GridView2" runat="server" DataSourceID="SqlDataSource2" 
        AllowPaging="True" PageSize="20" CellPadding="4" ForeColor="#333333" GridLines="None">
        <AlternatingRowStyle BackColor="White" />
        <EditRowStyle BackColor="#2461BF" />
        <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
        <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
        <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
        <RowStyle BackColor="#EFF3FB" />
        <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
        <SortedAscendingCellStyle BackColor="#F5F7FB" />
        <SortedAscendingHeaderStyle BackColor="#6D95E1" />
        <SortedDescendingCellStyle BackColor="#E9EBEF" />
        <SortedDescendingHeaderStyle BackColor="#4870BE" />

    </asp:GridView>

这是SqlDataSource

<asp:SqlDataSource ID="SqlDataSource2" runat="server" 
                    ConnectionString="<%$ ConnectionStrings:ConnectionString %>" 
                    ProviderName="<%$ ConnectionStrings:ConnectionString.ProviderName %>" 
                    SelectCommand="SELECT country AS Country,count(country) As Count FROM  client GROUP by country ORDER BY count(country) DESC;" ></asp:SqlDataSource>

我希望这个名字是这样的超链接:

/Details.aspx?country=countryname

我怎样才能实现它?

4

2 回答 2

4

在其中使用<TemplateField>带有HyperLink控件的 a,如下所示:

<asp:GridView ...>
    <Columns>
        <asp:TemplateField HeaderText="">
            <ItemTemplate>
                <asp:HyperLink runat="server" ID="HyperLink1" 
                    NavigateUrl='<%# "Details.aspx?country=" + Eval("Country")%>' 
                    Text='Details'>
                </asp:HyperLink>
            </ItemTemplate>
        </asp:TemplateField>
    </Columns>
</asp:GridView>
于 2013-10-23T21:13:48.157 回答
0

           <asp:HyperLink runat="server" ID="HyperLink1" 
               NavigateUrl='<%# "/Details.aspx?country=" + Eval("Country")%>' 
               Text='Details'>
           </asp:HyperLink>
于 2013-10-24T05:16:58.647 回答