1

I have this GridView in my page:

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

And this is the 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>

And i want that the name will be hyper link to somethis like this:

/Details.aspx?country=countryname

How i can implement it?

2 Answers 2

4

Use a <TemplateField> with a HyperLink control in it, like this:

<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>
Sign up to request clarification or add additional context in comments.

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.