473,420 Members | 4,511 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,420 software developers and data experts.

Move a row in a datalist

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
7 3061
"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
"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
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
"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
"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
"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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: pete K | last post by:
Is it possible in asp.net to have a datalist in the itemtemplate of another datalist? For example: <asp:datalist id="MyList" runat="server"> <ItemTemplate> <table border="0" width="300">...
10
by: Bharat | last post by:
Hi Folks, Suppose I have two link button on a page (say lnkBtn1 and lnkBtn2). On the click event of the lnkbtn1 I have to add a dynamically created control. And On the click event of the lnkBtn2 I...
4
by: Patrick.O.Ige | last post by:
I have a CheckBoxList in a DataList and i'm trying to get item Selected after doing a postBack. I have set my CheckBoxlist AutoPostBack="True" Any ideas what 'm doing wrong? It seems not to...
6
by: Paul | last post by:
I am trying to use a DataList and the ItemTemplate. I am binding the Datalist to a SQL query that gives me a list of Items with a Parent Category. I want to loop through all the items, but...
2
by: Hans Merkl | last post by:
Hi, I am trying to use a user control as EditItemTemplate in a DataList. It loads fine but I can't figure out how to bind to the data of the DataList. Here is what I have got so far: ...
3
by: Mirek Endys | last post by:
I have DataList as part of DataList item. DataList in DataList. The parent DataList working well including Edit command, that shows Edit template and correctly bind the data into edit template...
0
by: Les Caudle | last post by:
I have a menu system composed of a DataList nested inside a DataList. The outer DataList has it's DataSource (composed of a DataSet with two tables linked by a CategoryPagesRelation Relation) set...
1
by: AJ | last post by:
Hi all, With the following code in mind : <asp:DataList ID="dlOne" DataKeyField="myField1" DataSource="<%# GetDataSource1()" Runat="server"> <ItemTemplate> Output Value Here! <asp:DataList...
3
by: Crazy Cat | last post by:
Hi all, I am developing an asp.net 2.0 application in Visual Studio 2005. On my page I have a simple datalist that is bound programmatically to a collection of simple objects. On this page I...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.