473,385 Members | 1,843 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,385 software developers and data experts.

DataGrid binding problem

I have two datagrids on a page. On the update event of the first I take
some of the selected data, create a dataset and add it and then bind it to
the second datagrid. If I hit update several times it adds a new row to the
dataset and binds accordingly to the second datagrid. When I press cancel
and edit again the next update wipes the dataset that Iam binding to scond
datagrid. It is as if the cancel sets the dataset to nothing.

I am saving the dataset to a session on page unload and loading it in again
on the update command (or creating it for the first click on update) This is
code I use in the update event of the first datagrid. I have a feeling this
is something obvious but I am quite new to .net.

If IsNothing(Session("editteddataset")) Then
editteddataset = New DataSet()
editteddataset.ReadXmlSchema("C:\Inetpub\wwwroot\x mlxconfig\dseditted2.xsd")
Else
editteddataset = Session("editteddataset")
End If
Dim dsItem As DataRow
Dim dsTable As DataTable
dsTable = editteddataset.Tables("TABLEINFO")
dsItem = editteddataset.Tables("TABLEINFO").NewRow
Dim getcontroltype As DropDownList
getcontroltype = CType(e.Item.FindControl("controltype"), DropDownList)
dsItem("CONTROLTYPE") = getcontroltype.SelectedItem
dsTable.Rows.Add(dsItem)
'ds.WriteXml("c:\xmlconfig")
DataGrid2.Visible = True
DataGrid2.DataSource = editteddataset
DataGrid2.DataBind()
Nov 18 '05 #1
2 1098
Hi Chris,
I think that you probably have code like this in your Page_Unload:
Session("editteddataset") = editteddataset ..?

If you do, and editteddataset is not used or initialised during a page
postback, the member var editteddataset will remain as null (or Nothing in
VB), and on page_unload you will set it to null.

I think you would be better to set the dataset into the session only when
you create the actual dataset - i.e. add a line beneath your
editteddataset.ReadXmlSchema.. bit, doing the Session("editteddataset") =
editteddataset at that point. That, way you won't wipe it out on each page
postback which doesn't do anything with the dataset (like when the user
cancels).

HTH,
Cheers,
Pete Beech

"Chris Kennedy" <no****@nospam.co.uk> wrote in message
news:OO**************@TK2MSFTNGP12.phx.gbl...
I have two datagrids on a page. On the update event of the first I take
some of the selected data, create a dataset and add it and then bind it to
the second datagrid. If I hit update several times it adds a new row to the dataset and binds accordingly to the second datagrid. When I press cancel
and edit again the next update wipes the dataset that Iam binding to scond
datagrid. It is as if the cancel sets the dataset to nothing.

I am saving the dataset to a session on page unload and loading it in again on the update command (or creating it for the first click on update) This is code I use in the update event of the first datagrid. I have a feeling this is something obvious but I am quite new to .net.

If IsNothing(Session("editteddataset")) Then
editteddataset = New DataSet()
editteddataset.ReadXmlSchema("C:\Inetpub\wwwroot\x mlxconfig\dseditted2.xsd") Else
editteddataset = Session("editteddataset")
End If
Dim dsItem As DataRow
Dim dsTable As DataTable
dsTable = editteddataset.Tables("TABLEINFO")
dsItem = editteddataset.Tables("TABLEINFO").NewRow
Dim getcontroltype As DropDownList
getcontroltype = CType(e.Item.FindControl("controltype"), DropDownList)
dsItem("CONTROLTYPE") = getcontroltype.SelectedItem
dsTable.Rows.Add(dsItem)
'ds.WriteXml("c:\xmlconfig")
DataGrid2.Visible = True
DataGrid2.DataSource = editteddataset
DataGrid2.DataBind()

Nov 18 '05 #2
Sorry, that was a bit unclear - I meant to say in the second paragraph:

"If you do, and editteddataset is not used or initialised during a page
postback, the member var editteddataset will remain as null (or Nothing in
VB), and on page_unload you will reset it to null *** in the Session ***."

Pete

"Pete Beech" <pe*********@hotmail.nojunk.com> wrote in message
news:OV**************@tk2msftngp13.phx.gbl...
Hi Chris,
I think that you probably have code like this in your Page_Unload:
Session("editteddataset") = editteddataset ..?

If you do, and editteddataset is not used or initialised during a page
postback, the member var editteddataset will remain as null (or Nothing in
VB), and on page_unload you will set it to null.

I think you would be better to set the dataset into the session only when
you create the actual dataset - i.e. add a line beneath your
editteddataset.ReadXmlSchema.. bit, doing the Session("editteddataset") =
editteddataset at that point. That, way you won't wipe it out on each page
postback which doesn't do anything with the dataset (like when the user
cancels).

HTH,
Cheers,
Pete Beech

"Chris Kennedy" <no****@nospam.co.uk> wrote in message
news:OO**************@TK2MSFTNGP12.phx.gbl...
I have two datagrids on a page. On the update event of the first I take
some of the selected data, create a dataset and add it and then bind it to the second datagrid. If I hit update several times it adds a new row to the
dataset and binds accordingly to the second datagrid. When I press cancel and edit again the next update wipes the dataset that Iam binding to scond datagrid. It is as if the cancel sets the dataset to nothing.

I am saving the dataset to a session on page unload and loading it in

again
on the update command (or creating it for the first click on update) This is
code I use in the update event of the first datagrid. I have a feeling

this
is something obvious but I am quite new to .net.

If IsNothing(Session("editteddataset")) Then
editteddataset = New DataSet()

editteddataset.ReadXmlSchema("C:\Inetpub\wwwroot\x mlxconfig\dseditted2.xsd") Else
editteddataset = Session("editteddataset")
End If
Dim dsItem As DataRow
Dim dsTable As DataTable
dsTable = editteddataset.Tables("TABLEINFO")
dsItem = editteddataset.Tables("TABLEINFO").NewRow
Dim getcontroltype As DropDownList
getcontroltype = CType(e.Item.FindControl("controltype"), DropDownList)
dsItem("CONTROLTYPE") = getcontroltype.SelectedItem
dsTable.Rows.Add(dsItem)
'ds.WriteXml("c:\xmlconfig")
DataGrid2.Visible = True
DataGrid2.DataSource = editteddataset
DataGrid2.DataBind()


Nov 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Tom Hughes | last post by:
I want to change one field of all selected rows to a provided value. Problem 1 I am using the Binding Manager Base to bind the datagrid to the appropriate dataTable as recommended by KB817247....
5
by: Jeff | last post by:
IDE: VS 2003 :NET OS: XP Pro My app have a form with a tab-control on it. The tab-control have 2 tabpages. One of the tabpages displays a datagrid, and the other tabpage displays details (order...
4
by: Steve B. | last post by:
I have a DataGrid on the left and TextBoxes (TB) on the right. The TB's reflect the contents of the grid cells. Sorting of columns (both thru VS and programmatically) work fine except, when the...
0
by: Dave | last post by:
Tried posting in the Winform Forum without much luck, so posting here... After inserting a new data row to a DataTable that is bound to a datagrid, I am unable to change data in a row that is...
6
by: Alpha | last post by:
I have several textboxes that I need to chang the text when the selection row is changed in a datagrid. I have the following code. This textbox displayes the initial selection but when I click on...
3
by: vinayak | last post by:
Hi I am displaying data in Datagrid in ASP.NET with Edit/Update functionality for each row. On the same page I have 2 Button controls which submits the request to server. These button controls...
2
by: Brad Shook | last post by:
First of all thinks to Cor Ligthert for helping me with this last week. If you wild like to read Cor's comments please refer to the posting from 10/14/2004 and 8:48AM "Help with Advanced...
17
by: A_PK | last post by:
I have problem databinding the DataGrid with DataView/DataSet after the filter... I create the following proceudre in order for user to filter as many as they want, but the following code is only...
9
by: rn5a | last post by:
A Form has a DataGrid which displays records from a SQL Server 2005 DB table. Users can modify the records using this DataGrid for which I am using EditCommandColumn in the DataGrid. This is the...
2
by: =?Utf-8?B?Y3JlYXZlczA2MjI=?= | last post by:
I have a nested datagrid in a xaml file, the parent datagrid loads the vendor information and the details loads the documents for that vendor in a datagrid. Everything is working fine until I click...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...

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.