Gridview header issue: call event on header

Posted by Joris on Stack Overflow See other posts from Stack Overflow or by Joris
Published on 2010-04-23T11:39:57Z Indexed on 2010/04/23 11:43 UTC
Read the original article Hit count: 615

Filed under:
|
|
|

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. Also, when using a TemplateField, I find it very hard to fill the column with data. Could anyone bring me the solution?

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>

© Stack Overflow or respective owner

Related posts about c#

Related posts about ASP.NET