tshad said:
That sounds like it might work.
How do you keep the DataSet in a Session State?
You can store just about anything in Session state:
Session("data") = myDataSet
' later, or on another page:
Dim myDataSet = DirectCast(Session("data"), DataSet)
You have to check to make sure that Session("data") is not Nothing, and do
whatever you need to do to create and fill the DataSet in that case. It's
best to do this within a property or method so that the code to do it is all
in one place. Here's an example:
Private _dataSet As DataSet
Protected Property Data() As DataSet
Get
Dim table As DataTable
If Session("data") Is Nothing Then
' Do whatever you have to in order to get the data
' back into Session state
table = New DataTable("Table")
table.Columns.Add("column1", GetType(String))
table.Columns.Add("column2", GetType(String))
_dataSet = New DataSet("dataSet")
_dataSet.Tables.Add(table)
Session("data") = _dataSet
Else
_dataSet = DirectCast(Session("data"), DataSet)
End If
End Get
Set(ByVal Value As DataSet)
_dataSet = Value
Session("data") = _dataSet
End Set
End Property
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
If Not Page.IsPostBack Then
BindGrid()
End If
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim dr As DataRow = Data.Tables(0).NewRow()
dr("column1") = TextBox1.Text.Trim()
dr("column2") = TextBox2.Text.Trim()
Data.Tables(0).Rows.Add(dr)
'
BindGrid()
End Sub
' Separate sub is useful in case this gets fancier,
' with a DataView and sorting, for instance
Private Sub BindGrid()
Dim dv As New DataView
dv.Table = Data.Tables(0)
dv.Sort = "SortOrder"
DataGrid1.DataSource = dv
DataGrid1.DataBind()
End Sub
The sort order would be kept by letter or some number which I would change
(swap) with the the row above or below the row being moved. I would then
make the change to Sql Server using an update command.
How would I make the same change to the dataset?
' Find the appropriate row, however you do it, then:
dr("SortOrder") = newSortOrder ' Done
What about my grids? Would I lose the Grid data for each grid that is
connected to the rows?
No. You would call DataBind again, or better, call something like the
BindGrid in my example above.
John Saunders