Home > Archive > ASP .NET > May 2004 > DataGrid binding problem
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
DataGrid binding problem
|
|
| Chris Kennedy 2004-05-29, 11:39 am |
| 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()
| |
| Pete Beech 2004-05-29, 12:39 pm |
| 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" <nospam@nospam.co.uk> wrote in message
news:OOSjoXYREHA.2936@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\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()
>
>
| |
| Pete Beech 2004-05-29, 1:39 pm |
| 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" <peter_beech@hotmail.nojunk.com> wrote in message
news:OVnvkMZREHA.3988@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" <nospam@nospam.co.uk> wrote in message
> news:OOSjoXYREHA.2936@TK2MSFTNGP12.phx.gbl...
to[color=darkred]
> the
cancel[color=darkred]
scond[color=darkred]
> again
This[color=darkred]
> is
> this
>
editteddataset.ReadXmlSchema(" C:\Inetpub\wwwroot\xmlxconfig\dseditted2
.xsd")
>
>
|
|
|
|
|