Solved

asp.net gridview sorting not working correctly

Posted on 2011-03-23
3
409 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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

786 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