ProblemYou want to use a GridView and have its contents be updated without refreshing the whole page when the user performs a sort or paging operation. SolutionImplement the solution described in Recipe 2.14 and then set the EnableSortingAndPagingCallbacks attribute of the GridView to TRue. DiscussionThe GridView control provides built-in support for making callbacks to the server when a new sort order or page of data is requested by the user, and, in the process, retrieves the most recent data and updates the contents of the GridView, all without having to refresh the whole page. All you have to do to implement this capability is to set the EnableSortingAndPagingCallbacks attribute of the GridView to TRue. ASP.NET handles everything else for you. <asp:GridView Runat="Server" AllowPaging="true" AllowSorting="true" AutoGenerateColumns="false" BorderColor="#000080" BorderStyle="Solid" BorderWidth="2px" Caption="" HorizontalAlign="Center" Width="90%" PageSize="5" PagerSettings-Mode="Numeric" PagerSettings-PageButtonCount="5" PagerSettings-Position="Bottom" PagerStyle-HorizontalAlign="Center" PagerSettings-NextPageText="Next" PagerSettings-PreviousPageText="Prev" PagerStyle-Css OnRowCreated="gvBooks_RowCreated" EnableSortingAndPagingCallbacks="true" > ASP.NET handles the partial page refresh for you by outputting client-side JavaScript to perform an asynchronous callback to the server and handle the callback when the updated data is returned from the server. We won't delve into the JavaScipt here, but you can see it yourself by implementing the EnableSortingAndPagingCallbacks attribute in your application and then using the View Source command in the browser.
See AlsoRecipe 2.14 |