Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

asp.net gridview sorting not working correctly

Posted on 2011-03-23
3
Medium Priority
?
434 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 2000 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

722 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