Another useful feature in Gridview control is EnableSortingAndPagingCallbacks. If you set this property to true, then sorting and paging of Gridview will happen without page refresh. This feature will be very useful when you have a complex page with lots of controls including Gridview. Therefore, for sorting or paging a Gridview data you need not render the page again. Good thing here is it is done by framework. You just need to set this property to true. Framework will take care of doing callback and updating gridview back with new data. This feature uses callback feature of asp.net whidbey to do this. I have explained about callback feature in my previous blog.
Let us see how this EnableSortingandPaging Callback works,
<asp:GridView ID="GridView1" Runat="server" DataSourceID="SqlDataSource1"
AutoGenerateColumns="False" AllowSorting="True"
EnableSortingAndPagingCallbacks=true PageSize= 5 AllowPaging=true>
<Columns>
<asp:BoundField HeaderText="phone" DataField="phone" SortExpression="phone"/>
<asp:BoundField HeaderText="city" DataField="city" SortExpression="city"/>
<asp:BoundField HeaderText="state" DataField="state" SortExpression="state"/>
</Columns>
</asp:GridView>
If you set EnableSortingAndPagingCallbacks property to true, asp.net framework will insert necessary client side code to do callback when your press paging elements or sorting elements. The client scripts which are required for this callbacks are stored in WebResource.axd?a=s&r=GridView.js&t=632349364554375000 .
Note: You can view this file in Temporary Internet folders.
Similarly if you view the serverside code for implementing this feature, they have overridden RaiseCallBackEvent method of ICallbackEventHandler in Gridview.
string ICallbackEventHandler.RaiseCallbackEvent(string eventArgument)
{ // setting sorting key and paging index from event argument…
HtmlTextWriter writer2 = new HtmlTextWriter(writer1);
this.DataBind();
this.RenderTableContents(writer2);
writer2.Flush();
writer2.Close();
string text2 = formatter1.Serialize(this.SaveDataKeysState());
object[] objArray1 = new object[11] { "\"", this.PageIndex, "|", (int) this.SortDirection, "|", this.SortExpression, "|", text2, "|", writer1.ToString(), "\"" } ; return string.Concat(objArray1);
}
In this, they are setting page index, sorting key and rebinding the GridView. After rebinding, they are extracting the HTML elements from GridView and then sending that to client. Client script will replace this Gridview data with these new HTML elements.
Note: I didnt cover about how Gridview is maintaining page index and sorting key between postbacks and callbacks. In addition, there is one issue with this is explained by Dino in this article.
I thought of implementing this feature for Auto refresh Datagrid in ASP.NET 1.1 in a similar manner.
I think Microsoft can think of implementing AutoRefresh GridView. They need to have Autorefresh property to Gridview. This property will help GridView to automatically refresh after certain interval. You can mention the interval time also. It can use the same framework of EnableSortingAndPagingCallbacks. I have seen many questions about Autorefresh Datagrid in newsgroups. If many people require this feature, I think they can include this feature.
If any of you require similar feature (Auto Refresh GridView), then post your comments here.
Last month I blogged about SyncWithAD_Lookup error during VSTS Installation. John Lawrence (Development manager in Microsoft VSTS Team) posted a comment for that blog today. Microsoft accepted this as a bug in this release and it will be fixed in next release. This information has been posted in VSTS Team blog. What I am impressed with this is, Microsoft's interest in customer feedback to improve their product. I just posted about this error in my blog, I didnt event post it in Microsoft Feedback Center. However, they noticed this blog and took it as a feedback. Not only this, I have posted two bugs(1 and 2) in Microsoft Feedback Center. For that also, I got replies within two to three weeks times.. All this proves that Microsoft is listening to customer constantly...
So guys, if you have any feedback or comments about Microsoft Products. Post it.. Microsoft will listen to you...