Recipe 2.16. Updating a GridView Without Refreshing the Whole Page


Problem

You 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.

Solution

Implement the solution described in Recipe 2.14 and then set the EnableSortingAndPagingCallbacks attribute of the GridView to TRue.

Discussion

The 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.

The ability to update the contents of a GridView without refreshing the whole page is not supported in all browsers. Only Internet Explorer 5.5 (and later), Netscape 6.0 (and later), and Firefox are supported.


See Also

Recipe 2.14



ASP. NET Cookbook
ASP.Net 2.0 Cookbook (Cookbooks (OReilly))
ISBN: 0596100647
EAN: 2147483647
Year: 2003
Pages: 202

Similar book on Amazon

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net