DataGrid, ViewState and SelectedIndex
The ViewState of an ASP.NET page is a hidden field that the ASP.NET framework uses to maintain the state of a web page. When a user posts a page to the server, the server will restore the contents of the controls by parsing out the state and restoring the state in the Base64 encoded field.
If you've worked with the DataGrid you know it has a tendency to increase the contents of the ViewState field by quite a bit - sometimes in excess of 100KB! To combat this, a variety of methods are employed - from overriding the Page.SavePagetoPersistenceMedium and Page.LoadPageFromPersistenceMedium and serializing it to Session state to the most obvious - setting the EnableViewState property to false. Saving the view state to Session can have scalability issues, but for web sites with minimal traffic this may be an option. The better solution IMHO is to remove disable the ViewState for the DataGrid by setting the EnableViewState property to false.
A couple of additional issues rear their heads when you do this however. For starters, you must rebind your data to the Grid on every postback instead of the traditional (!isPostBack) check. You can cache this data yourself in the Page.Cache object to mitigate the database hit issue so that is no problem. As well, you will find out that the SelectedIndex property is now one post behind. This is due to the Page Life Cycle, whereby the SelectedIndexChanged event fires after the Load event. The SelectedIndex property is set correctly but it doesn't get set until after you bind. The solution is to rebind in the OnPreRender event instead.
By setting the EnableViewState to false on my pages, I've reduced the size of the Request and Response by over 60% with no loss of funtionality.