Persist DataSet in ViewState
This is for registering for swimming lesson sessions for the summer. The temporary (local on the client) table would hold one swimmer's registration for the summer (can't see how he could attend more than 4-5). Adds and deletes would be posted to the main database at the end of the session kind of like a shopping cart. The sessions would be like someone registering for a school semester on-line. Since only a half-dozen rows in the table would be involved it seemed possible to work with that underlying table since it was already bound to the GridView. I have never worked with a cache like a reply suggests but maybe that makes more sense.
A selection is made from another GridView and the row is added to the
underlying table of the first GridView. The ViewState of a GridView seems to work just fine when a SQL operation on the database on the server takes place and the DataSource is bound again, so a small, persisted working table bound to its own grid seems logical. However, its the working table between postbacks that collects the adds and deletes that's critical. Here's the abbreviated code which creates, saves and restores the ViewState:
Sub Page_Load
If Not Page.IsPostBack Then
'stmts to create dataset and table
ViewState("aquatic") = dsAqua
Else
dsAqua = CType(ViewState("aquatic"), DataSet)
dtLesson = dsAqua.Tables("lesson")
End If
End Sub
Sub gridSessions_SelectedIndexChanged
Dim rowSession As GridViewRow = gridSessions.SelectRow
Dim drLesson As DataRow
drLesson = dtLesson.NewRow()
drLesson.Item("lessonid") = 0
etc.
End Sub
In the page lifecycle postback events occur after load the event should act on the restored DataSet from Page_Load. But there is no schema from the DataTable returned. Maybe saving a DataSet in ViewState is not possible. But if you can keep track of a cache associated with a session and process it at the end maybe that makes more sense. I'll have to study the (Wrox etc.) books I have on it.
|