DataGrid binding problem

C

Chris Kennedy

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\xmlxconfig\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()
 
P

Pete Beech

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
 
P

Pete Beech

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top