Solved

asp.net gridview sorting not working correctly

Posted on 2011-03-23
3
402 Views
Last Modified: 2012-05-11
I am using a grdview control and I have enabled sorting however when I click on the sort hyperlink in the title column it never calls the GridView1_Sorting routine.  Pretty much nothing happens, there is no post back.  What else do I need to enable to get post back to work.

When I hover over the link it says "javascript:__doPostBack('GridView1','Sort$Employee_id ASC')

(I have not included the sorting routine, however when I put a debug breakpoint on the sorting or selected indexchanged routine they are never called.

What am I missing?
<asp:GridView ID="GridView1" runat="server" CellPadding="4" 
            EnableModelValidation="True" ForeColor="#333333" GridLines="None" 
            AutoGenerateColumns="False" AllowSorting="True" 
            EnableSortingAndPagingCallbacks="True"
            OnSorting="gridView1_Sorting" AutoGenerateSelectButton="False" 
            AutoGenerateEditButton="False" AllowPaging="True" PageSize="999">
        <AlternatingRowStyle BackColor="White" Font-Bold="True" ForeColor="#000000"  HorizontalAlign="Center" />
        <EditRowStyle BackColor="#999999" />
        <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
        <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" Font-Size="Small" />
        <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
        <RowStyle BackColor="#E3E0D7" ForeColor="#000000" Font-Size="Small" Font-Bold="True" HorizontalAlign="Center" />
        <SelectedRowStyle BackColor="#D9D3CA" Font-Bold="True" ForeColor="#000000" />
    <Columns>
                                                    <asp:BoundField DataField="employee_id" HeaderText="Emp #" 
                                                            HtmlEncode="False" HtmlEncodeFormatString="False" ItemStyle-HorizontalAlign="Left" SortExpression="employee_id ASC" />

============

    Public Sub GridView1_Sorting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewSortEventArgs) Handles GridView1.Sorting
        Dim m_DataTable As DataTable = GridView1.DataSource

    End Sub

    Protected Sub GridView1_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs) Handles GridView1.SelectedIndexChanged
        Dim m_DataTable As DataTable = GridView1.DataSource

    End Sub

Open in new window

0
Comment
Question by:TedgCl
  • 2
3 Comments
 
LVL 29

Expert Comment

by:Paul Jackson
ID: 35201889
How are you binding the gridview to a datasource. It would be useful if you could post this code.
0
 

Author Comment

by:TedgCl
ID: 35201933
During page load I call a SQL procedure which builds a table.  I then create a dataview and bind that to the gridview.
So the databind event is called during page_load.

Dim dv As DataView = New DataView(PTable)
                GridView1.DataSource = dv
                GridView1.DataBind()

However there is no postBack ever called when the sort buttons are clicked.
0
 
LVL 29

Accepted Solution

by:
Paul Jackson earned 500 total points
ID: 35202054
remove the following setting from the gridview definition it is specifying that you want to use client-side callbacks to handle the sorting and therefore the server postback won't happen:
EnableSortingAndPagingCallbacks="True"
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This video discusses moving either the default database or any database to a new volume.

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now