Solved

asp.net gridview sorting not working correctly

Posted on 2011-03-23
3
426 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

622 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