Ok, here's an alternative approach to persisting data without a dataset in cache for ASP .NET:
Save the dataset schema information to the viewstate and populate it from the grid items. Just FYI I'm manually building a dataset in this example. In the real environment I'll be calling a webservice to get it. I hope no one else ever has requirements like mine
Dim ds As DataSet
Private
Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
ds =
New DataSet
If Not IsPostBack Then
ds.Tables.Add(
New DataTable)
ds.Tables(0).Columns.Add(
"ID")
ds.Tables(0).Columns.Add(
"Text")
Dim dr As DataRow = ds.Tables(0).NewRow()
dr.Item(0) =
"1"
dr.Item(1) =
"SomeText"
ds.Tables(0).Rows.Add(dr)
dr = ds.Tables(0).NewRow()
dr.Item(0) =
"2"
dr.Item(1) =
"MoreText"
ds.Tables(0).Rows.Add(dr)
grid1.DataSource = ds.Tables(0).DefaultView
grid1.DataBind()
ViewState.Add(
"MySchema", ds.GetXmlSchema)
Else
BuildGridDataSource()
End If
End Sub
Private Sub AddRow()
Dim dRow As DataRow
dRow = ds.Tables(0).NewRow
dRow.Item(0) = ds.Tables(0).Rows.Count + 1
dRow.Item(1) =
"New Row"
ds.Tables(0).Rows.Add(dRow)
grid1.DataSource = ds.Tables(0).DefaultView
grid1.DataBind()
End Sub
Private Sub BuildGridDataSource()
Dim oStringReader As New IO.StringReader(ViewState("MySchema").ToString)
ds.ReadXmlSchema(oStringReader)
Dim oGridItem As DataGridItem
Dim oGridCell As TableCell
Dim dRow As DataRow
For Each oGridItem In grid1.Items
dRow = ds.Tables(0).NewRow
Dim iColPos As Integer = 0
For Each oGridCell In oGridItem.Cells
dRow.Item(iColPos) = oGridCell.Text
iColPos += 1
Next
ds.Tables(0).Rows.Add(dRow)
Next
grid1.DataSource = ds.Tables(0).DefaultView
grid1.DataBind()
End Sub
Posted
Fri, Jul 2 2004 6:09 AM
by
Eric Wise