Spread for ASP.NET 8.0 Product Documentation > Developer's Guide > Maintaining State > Saving Data to the View State |
View state management provides client-based state management, where data is written into pages in hidden fields.
To save the data to the view state, set the IsTrackingViewState property for the active sheet to true, which is the default setting.
The advantages of using the view state are:
The default control settings use the view state to save data. This default setting is best for small data models. If you are using larger data sets, you will probably want to use one of the other state management options
The disadvantage of using view state is the impact on performance. Because the view state is stored in the page itself, storing large values can cause the page to slow down when users display it and when they post it.
Use the view state to save data.
The following sample illustrates using the view state to save data.
C# |
Copy Code
|
---|---|
protected void Page_Load(object sender, System.EventArgs e) { if (this.IsPostBack) return; // Connect to NWIND MS Access example with OLE DB. OleDbConnection thisConnection = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=D:\\NWIND.MDB"); // Open connection. thisConnection.Open(); // Create DataSet to contain related data tables, rows, and columns. DataSet thisDataSet = new DataSet(); OleDbDataAdapter orderAdapter = new OleDbDataAdapter("SELECT EmployeeID, LastName, FirstName, Title FROM Employees", thisConnection); orderAdapter.Fill(thisDataSet, "Employees"); FpSpread1.ActiveSheetView.IsTrackingViewState = true; FpSpread1.ActiveSheetView.DataSource = thisDataSet; FpSpread1.ActiveSheetView.DataMember = "Employees"; thisConnection.Close(); thisConnection.Dispose(); } |
VB |
Copy Code
|
---|---|
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load If (Me.IsPostBack) Then Return ' Connect to NWIND MS Access example with OLE DB. Dim thisConnection As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=D:\NWIND.MDB") ' Open connection. thisConnection.Open() ' Create DataSet to contain related data tables, rows, ' and columns. Dim thisDataSet As New DataSet() Dim orderAdapter As New OleDbDataAdapter("SELECT EmployeeID, LastName, FirstName, Title FROM Employees", thisConnection) orderAdapter.Fill(thisDataSet, "Employees") FpSpread1.ActiveSheetView.IsTrackingViewState = True FpSpread1.ActiveSheetView.DataSource = thisDataSet FpSpread1.ActiveSheetView.DataMember = "Employees" thisConnection.Close() thisConnection.Dispose() End Sub |