Jesse Ezell
1/4/2003 9:27:00 PM
This is not what ViewState is intended to do. You can
transfer a lot of the current requests information to
another page with Server.Transfer. Heavy use of ViewState
is not recommended either. It is mainly for storing minor
bits of information, so with your datagrids all using
ViewState, I can see how it might be a problem with 3
datagrids.
What you might want to do is store the data that is being
binded in session, along with some other info that you
need such as current page, selected index, etc. (this is
called a 'Memento' pattern...you can read about it "Gang
of Four" [Design Patterns, Eric Gamma]...the best books
ever written on software patterns, a highly recommended
read). Then, you don't have to run the query over an over
again.
A class like this would do the trick:
public class DataGridState
{
public string ID;
public int CurrentPage;
public int SelectedIndex;
public object DataSource;
public string CurrentSortExpression;
}
Of course, only include the bare minimum that you need to
restore the state.
Now, if you want to automate the process, or make it so
that it works across many types of objects without much
additional code, you could create a custom viewstate to
memento transfer class that uses reflection and
attributes to handle syncronization of your mememento
object with the datagrid and the session.
--Jesse