【问题标题】:GridView with Hyperlink column带有超链接列的 GridView
【发布时间】:2013-10-24 13:16:58
【问题描述】:

我的页面中有这个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

我如何实现它?

【问题讨论】:

    标签: c# asp.net .net


    【解决方案1】:

    使用带有HyperLink 控件的&lt;TemplateField&gt;,如下所示:

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

    【讨论】:

      【解决方案2】:

                 <asp:HyperLink runat="server" ID="HyperLink1" 
                     NavigateUrl='<%# "/Details.aspx?country=" + Eval("Country")%>' 
                     Text='Details'>
                 </asp:HyperLink>
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-12-05
        • 1970-01-01
        相关资源
        最近更新 更多