views:

149

answers:

3

Hi,

I want the headers of my gridview to be hyperlinks, without the "SortExpression"... I searched the net, but I've been not very succesful.

Anyone has the solution?

For example: when clicking on the header of a simple gridview, the site navigates to a webpage. Is it possible?

Thanks in advance!

A: 

I think a HeaderTemplate is needed here...

Ref.: http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.templatefield.headertemplate.aspx

HTH.

Sunny
A: 

Have you tried Gridview Header template like...

 <asp:GridView runat="server" ID="grd">
        <Columns>
            <asp:TemplateField>
                <HeaderTemplate>
                    <asp:HyperLink runat="server" NavigateUrl="YourURL"> </asp:HyperLink>
                </HeaderTemplate>
            </asp:TemplateField>
        </Columns>
    </asp:GridView>
Muhammad Akhtar
Yes! Thank you!Only thing: make sure to insert the "Text" element, as that becomes the actual link...
Joris
A: 

Now I got this gridview, And I need the headers to be clickable, whereafter an event starts (something like OnClickHeader="header_ClickEvent"?) Ofcourse there is a SortExpression element, which enables to sort the grid, but I want to be able to start any event, like when clicking a button.

I could not find any solution within the asp:BoundField nor asp:TemplateField... I thought a hyperlink could solve the problem, but that was a bit premature.

The Gridview:

<asp:GridView CssClass="gridview" ID="GridView1" runat="server" AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False" DataKeyNames="Student_key" OnSelectedIndexChanged="GridView1_SelectedIndexChanged" PagerSettings-Visible="false" PageSize="14">

                                    <HeaderStyle CssClass="headerstyle" />
                                    <RowStyle CssClass="rowstyle"/>
                                    <AlternatingRowStyle CssClass="altrowstyle" />
                                    <Columns>
                                        <asp:BoundField DataField="Studentnumber" HeaderText="Studentnummer" >
                                            <HeaderStyle CssClass="header100" />
                                        </asp:BoundField>
                                        <asp:BoundField DataField="Prefix" HeaderText="Voorletters" >
                                            <HeaderStyle CssClass="header75" />
                                        </asp:BoundField>
                                        <asp:BoundField DataField="prename" HeaderText="Voornaam" SortExpression="Voornaam">
                                            <HeaderStyle CssClass="header75" />
                                        </asp:BoundField>
                                        <asp:BoundField DataField="nickname" HeaderText="Roepnaam" >
                                            <HeaderStyle CssClass="header100" />
                                        </asp:BoundField>
                                        <asp:BoundField DataField="insertion" HeaderText="Tussenvoegsel" >
                                            <HeaderStyle CssClass="header100" />
                                        </asp:BoundField>
                                        <asp:BoundField DataField="surname" HeaderText="Achternaam">
                                            <HeaderStyle CssClass="header100" />
                                        </asp:BoundField>
                                        <asp:CommandField SelectText="show results" ShowSelectButton="True" >
                                            <HeaderStyle CssClass="header100" />
                                        </asp:CommandField>

                                    </Columns>
                                    <EmptyDataTemplate >There are no results shown, please try again.</EmptyDataTemplate>

                                </asp:GridView>
Joris