0

I'm trying to sort the columns for a GridView in ASP.Net, ideally without refreshing the page.

My data is compiled into a generic list on the server and bound to the GridView in the code-behind.

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
BackColor="White" CellPadding="3" GridLines="Vertical" AllowSorting="True" 
CssClass="GridViewStyle" EnableSortingAndPagingCallbacks="True" 
AllowPaging="True">
    <Columns>
      <asp:BoundField DataField="ID" HeaderText="ID" SortExpression="ID">
      </asp:BoundField>
      <asp:BoundField DataField="Title" HeaderText="Title" SortExpression="Title">
      </asp:BoundField>                            
      <asp:BoundField DataField="Customer" HeaderText="Customer" SortExpression="Customer">
      </asp:BoundField>                            
    </Columns>

When I try to click any of the column headers, nothing happens.

Is there any way to accomplish this without refreshing the page?

1
  • No with asp.net Gridview component, because is a server component. It doesn't have almost any client behavior. You will need to use some other type of component, either a javascript component or something hybrid. Commented Apr 26, 2017 at 20:30

1 Answer 1

3

No, there is no way to accomplish this with a Gridview alone without causing a postback.

You can sort it on the client side with JavaScript (perhaps by abandoning GridView and instead using a Repeater combined with jQuery DataTables)

Or you can use an UpdatePanel or iframe to mask the postback. Those have their own complications and are probably not the best approach however. I personally absolutely hate using either of them and recommend you steer clear.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.