By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,088 Members | 1,326 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,088 IT Pros & Developers. It's quick & easy.

Move a row in a datalist

P: n/a
Is there a way to move a row in a Datalist up or down without having to
re-read the data?

I have a datalist which has embedded Datagrids in it. I want to allow the
user to move a row up or down by just pushing a button and have the page
post back with the row moved without actually re-reading the data from the
database?

Thanks,

Tom.
Nov 19 '05 #1
Share this Question
Share on Google+
7 Replies


P: n/a
"tshad" <ts**********@ftsolutions.com> wrote in message
news:uP**************@TK2MSFTNGP09.phx.gbl...
Is there a way to move a row in a Datalist up or down without having to
re-read the data?

I have a datalist which has embedded Datagrids in it. I want to allow the
user to move a row up or down by just pushing a button and have the page
post back with the row moved without actually re-reading the data from the
database?


If the DataList is data bound, then the order of the rows is the order of
the data. Somehow, you'll have to change the order of the data when the user
drags the row.

John Saunders
Nov 19 '05 #2

P: n/a
"John Saunders" <johnwsaundersiii at hotmail.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
"tshad" <ts**********@ftsolutions.com> wrote in message
news:uP**************@TK2MSFTNGP09.phx.gbl...
Is there a way to move a row in a Datalist up or down without having to
re-read the data?

I have a datalist which has embedded Datagrids in it. I want to allow
the user to move a row up or down by just pushing a button and have the
page post back with the row moved without actually re-reading the data
from the database?
If the DataList is data bound, then the order of the rows is the order of
the data. Somehow, you'll have to change the order of the data when the
user drags the row.


The data is databound and if they make a change, then I will change the
data, but I don't want to have to reread the data to re-fill the datalist,
which would entail reading the data to fill the grids also.

Tom.
John Saunders

Nov 19 '05 #3

P: n/a
You can achieve it with heavy javascripting. And you will need to find a way
of transferring new order back to server. Something like merging item values
into one string, passing it in a hidden <input>, parsing on the server and
setting new order in the database. Quite a challenging task.

Eliyahu

"tshad" <ts**********@ftsolutions.com> wrote in message
news:%2***************@TK2MSFTNGP12.phx.gbl...
"John Saunders" <johnwsaundersiii at hotmail.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
"tshad" <ts**********@ftsolutions.com> wrote in message
news:uP**************@TK2MSFTNGP09.phx.gbl...
Is there a way to move a row in a Datalist up or down without having to
re-read the data?

I have a datalist which has embedded Datagrids in it. I want to allow
the user to move a row up or down by just pushing a button and have the
page post back with the row moved without actually re-reading the data
from the database?


If the DataList is data bound, then the order of the rows is the order of the data. Somehow, you'll have to change the order of the data when the
user drags the row.


The data is databound and if they make a change, then I will change the
data, but I don't want to have to reread the data to re-fill the datalist,
which would entail reading the data to fill the grids also.

Tom.

John Saunders


Nov 19 '05 #4

P: n/a
"tshad" <ts**********@ftsolutions.com> wrote in message
news:%2***************@TK2MSFTNGP12.phx.gbl...
"John Saunders" <johnwsaundersiii at hotmail.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
"tshad" <ts**********@ftsolutions.com> wrote in message
news:uP**************@TK2MSFTNGP09.phx.gbl...
Is there a way to move a row in a Datalist up or down without having to
re-read the data?

I have a datalist which has embedded Datagrids in it. I want to allow
the user to move a row up or down by just pushing a button and have the
page post back with the row moved without actually re-reading the data
from the database?


If the DataList is data bound, then the order of the rows is the order of
the data. Somehow, you'll have to change the order of the data when the
user drags the row.


The data is databound and if they make a change, then I will change the
data, but I don't want to have to reread the data to re-fill the datalist,
which would entail reading the data to fill the grids also.


Ok, what if you keep the data in a DataSet in Session state. Databind it to
the DataList through a DataView. Have the DataView sorted by a SortOrder
column. Have the row move change the SortOrder field of the dropped row and
those following its new position. When you DataBind again, the moved row
should be in its new position.

John Saunders
Nov 19 '05 #5

P: n/a
"John Saunders" <johnwsaundersiii at hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
"tshad" <ts**********@ftsolutions.com> wrote in message
news:%2***************@TK2MSFTNGP12.phx.gbl...
"John Saunders" <johnwsaundersiii at hotmail.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
"tshad" <ts**********@ftsolutions.com> wrote in message
news:uP**************@TK2MSFTNGP09.phx.gbl...
Is there a way to move a row in a Datalist up or down without having to
re-read the data?

I have a datalist which has embedded Datagrids in it. I want to allow
the user to move a row up or down by just pushing a button and have the
page post back with the row moved without actually re-reading the data
from the database?

If the DataList is data bound, then the order of the rows is the order
of the data. Somehow, you'll have to change the order of the data when
the user drags the row.
The data is databound and if they make a change, then I will change the
data, but I don't want to have to reread the data to re-fill the
datalist, which would entail reading the data to fill the grids also.


Ok, what if you keep the data in a DataSet in Session state. Databind it
to the DataList through a DataView. Have the DataView sorted by a
SortOrder column. Have the row move change the SortOrder field of the
dropped row and those following its new position. When you DataBind again,
the moved row should be in its new position.


That sounds like it might work.

How do you keep the DataSet in a Session State?

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?

What about my grids? Would I lose the Grid data for each grid that is
connected to the rows?

Thanks,

Tom.
John Saunders

Nov 19 '05 #6

P: n/a
"tshad" <ts**********@ftsolutions.com> wrote in message
news:eT**************@TK2MSFTNGP15.phx.gbl...
"John Saunders" <johnwsaundersiii at hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
"tshad" <ts**********@ftsolutions.com> wrote in message
news:%2***************@TK2MSFTNGP12.phx.gbl...
"John Saunders" <johnwsaundersiii at hotmail.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
"tshad" <ts**********@ftsolutions.com> wrote in message
news:uP**************@TK2MSFTNGP09.phx.gbl...
> Is there a way to move a row in a Datalist up or down without having
> to re-read the data?
>
> I have a datalist which has embedded Datagrids in it. I want to allow
> the user to move a row up or down by just pushing a button and have
> the page post back with the row moved without actually re-reading the
> data from the database?

If the DataList is data bound, then the order of the rows is the order
of the data. Somehow, you'll have to change the order of the data when
the user drags the row.

The data is databound and if they make a change, then I will change the
data, but I don't want to have to reread the data to re-fill the
datalist, which would entail reading the data to fill the grids also.
Ok, what if you keep the data in a DataSet in Session state. Databind it
to the DataList through a DataView. Have the DataView sorted by a
SortOrder column. Have the row move change the SortOrder field of the
dropped row and those following its new position. When you DataBind
again, the moved row should be in its new position.


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
Nov 19 '05 #7

P: n/a
Hi,

In addition to adding the dataset, which contains the datatable to the
Session, you can add a datacolumn called "Order" and fill it with the number
in which the client selects the order of the datarows. And you can create a
dataview, sort it with the "Order" column and bind it to datagrid.

Hope it helps.

Prakash.C

"John Saunders" wrote:
"tshad" <ts**********@ftsolutions.com> wrote in message
news:eT**************@TK2MSFTNGP15.phx.gbl...
"John Saunders" <johnwsaundersiii at hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
"tshad" <ts**********@ftsolutions.com> wrote in message
news:%2***************@TK2MSFTNGP12.phx.gbl...
"John Saunders" <johnwsaundersiii at hotmail.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
> "tshad" <ts**********@ftsolutions.com> wrote in message
> news:uP**************@TK2MSFTNGP09.phx.gbl...
>> Is there a way to move a row in a Datalist up or down without having
>> to re-read the data?
>>
>> I have a datalist which has embedded Datagrids in it. I want to allow
>> the user to move a row up or down by just pushing a button and have
>> the page post back with the row moved without actually re-reading the
>> data from the database?
>
> If the DataList is data bound, then the order of the rows is the order
> of the data. Somehow, you'll have to change the order of the data when
> the user drags the row.

The data is databound and if they make a change, then I will change the
data, but I don't want to have to reread the data to re-fill the
datalist, which would entail reading the data to fill the grids also.

Ok, what if you keep the data in a DataSet in Session state. Databind it
to the DataList through a DataView. Have the DataView sorted by a
SortOrder column. Have the row move change the SortOrder field of the
dropped row and those following its new position. When you DataBind
again, the moved row should be in its new position.


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

Nov 19 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.