473,657 Members | 2,776 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 3091
"tshad" <ts**********@f tsolutions.com> wrote in message
news:uP******** ******@TK2MSFTN GP09.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" <johnwsaundersi ii at hotmail.com> wrote in message
news:%2******** ********@tk2msf tngp13.phx.gbl. ..
"tshad" <ts**********@f tsolutions.com> wrote in message
news:uP******** ******@TK2MSFTN GP09.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**********@f tsolutions.com> wrote in message
news:%2******** *******@TK2MSFT NGP12.phx.gbl.. .
"John Saunders" <johnwsaundersi ii at hotmail.com> wrote in message
news:%2******** ********@tk2msf tngp13.phx.gbl. ..
"tshad" <ts**********@f tsolutions.com> wrote in message
news:uP******** ******@TK2MSFTN GP09.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**********@f tsolutions.com> wrote in message
news:%2******** *******@TK2MSFT NGP12.phx.gbl.. .
"John Saunders" <johnwsaundersi ii at hotmail.com> wrote in message
news:%2******** ********@tk2msf tngp13.phx.gbl. ..
"tshad" <ts**********@f tsolutions.com> wrote in message
news:uP******** ******@TK2MSFTN GP09.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" <johnwsaundersi ii at hotmail.com> wrote in message
news:%2******** ********@TK2MSF TNGP15.phx.gbl. ..
"tshad" <ts**********@f tsolutions.com> wrote in message
news:%2******** *******@TK2MSFT NGP12.phx.gbl.. .
"John Saunders" <johnwsaundersi ii at hotmail.com> wrote in message
news:%2******** ********@tk2msf tngp13.phx.gbl. ..
"tshad" <ts**********@f tsolutions.com> wrote in message
news:uP******** ******@TK2MSFTN GP09.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**********@f tsolutions.com> wrote in message
news:eT******** ******@TK2MSFTN GP15.phx.gbl...
"John Saunders" <johnwsaundersi ii at hotmail.com> wrote in message
news:%2******** ********@TK2MSF TNGP15.phx.gbl. ..
"tshad" <ts**********@f tsolutions.com> wrote in message
news:%2******** *******@TK2MSFT NGP12.phx.gbl.. .
"John Saunders" <johnwsaundersi ii at hotmail.com> wrote in message
news:%2******** ********@tk2msf tngp13.phx.gbl. ..
"tshad" <ts**********@f tsolutions.com> wrote in message
news:uP******** ******@TK2MSFTN GP09.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(Sess ion("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("Tabl e")
table.Columns.A dd("column1", GetType(String) )
table.Columns.A dd("column2", GetType(String) )
_dataSet = New DataSet("dataSe t")
_dataSet.Tables .Add(table)
Session("data") = _dataSet
Else
_dataSet = DirectCast(Sess ion("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.EventArg s) Handles MyBase.Load
If Not Page.IsPostBack Then
BindGrid()
End If
End Sub

Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button1.Click
Dim dr As DataRow = Data.Tables(0). NewRow()
dr("column1") = TextBox1.Text.T rim()
dr("column2") = TextBox2.Text.T rim()
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.DataS ource = dv
DataGrid1.DataB ind()
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**********@f tsolutions.com> wrote in message
news:eT******** ******@TK2MSFTN GP15.phx.gbl...
"John Saunders" <johnwsaundersi ii at hotmail.com> wrote in message
news:%2******** ********@TK2MSF TNGP15.phx.gbl. ..
"tshad" <ts**********@f tsolutions.com> wrote in message
news:%2******** *******@TK2MSFT NGP12.phx.gbl.. .
"John Saunders" <johnwsaundersi ii at hotmail.com> wrote in message
news:%2******** ********@tk2msf tngp13.phx.gbl. ..
> "tshad" <ts**********@f tsolutions.com> wrote in message
> news:uP******** ******@TK2MSFTN GP09.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(Sess ion("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("Tabl e")
table.Columns.A dd("column1", GetType(String) )
table.Columns.A dd("column2", GetType(String) )
_dataSet = New DataSet("dataSe t")
_dataSet.Tables .Add(table)
Session("data") = _dataSet
Else
_dataSet = DirectCast(Sess ion("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.EventArg s) Handles MyBase.Load
If Not Page.IsPostBack Then
BindGrid()
End If
End Sub

Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button1.Click
Dim dr As DataRow = Data.Tables(0). NewRow()
dr("column1") = TextBox1.Text.T rim()
dr("column2") = TextBox2.Text.T rim()
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.DataS ource = dv
DataGrid1.DataB ind()
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
1765
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"> <tr> <td><%# DataBinder.Eval(Container.DataItem, "title") %></td>
10
2844
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 have to add a datalist control. Using this datalist control I should be able to add edit, modify and cancel the items listed in this control. Here is how I designed. I used placeholder to add the controls dynamically to the page on the click...
4
4034
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 work:( Thanks My CheckBoxList in the DataList Below
6
9584
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 only print the Parent Category once, regardless of how many child items are in it. So my perfect output would look something like:
2
3436
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: //Page_load of my user control protected void Page_Load(object sender, EventArgs e) { IDataItemContainer DataContainer = this.Parent as
3
10292
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 (where is the child DataList).... But in case I want to make Edit in this child DataList it is not working... No edit template showed... :( this is a code that i use for the child DataList... Edit command // this is for child DataList...
0
1642
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 in the Page_Load. The inner DataList has its DataSource set in the ascx file as: <asp:DataList ID="PageList" runat="server" CellPadding="3" CellSpacing="0" DataSource='<%#...
1
2659
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 ID="dlTwo" DataKeyField="myField2" DataSource="<%# GetDataSource2(?,?)" Runat="server">
3
2804
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 need to control the visibility of a textbox based on a dropdown selection in the datalist's edititem template. To do this, I registered a client script block function and attached a client side handler for the dropdownlist's onchange event in the...
0
8737
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8509
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8610
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7345
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6174
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4327
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2735
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1967
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1730
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.