Link to home
Start Free TrialLog in
Avatar of TedgCl
TedgCl

asked on

asp.net gridview sorting not working correctly

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

Avatar of Paul Jackson
Paul Jackson
Flag of United Kingdom of Great Britain and Northern Ireland image

How are you binding the gridview to a datasource. It would be useful if you could post this code.
Avatar of TedgCl
TedgCl

ASKER

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.
ASKER CERTIFIED SOLUTION
Avatar of Paul Jackson
Paul Jackson
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial