Creating or Getting a Dataset from a grid

  • Thread starter Thread starter Filippo Pandiani
  • Start date Start date
F

Filippo Pandiani

I have a grid that shows the file list from a folder.
On the postback, how do I get a Dataset from this grid?


Thanks,
Filippo.
 
Hi Filippo,

The grid is intended to work as a view of a data backend ( like a dataset )
it's not intended as a datasource , it's possible to take a grid and build a
data collection with it, basically a collection or records ( you can view
this as a array or a table), you could create a dataset with a table that
contain the same number of columns that cells has a grid's row.

Now this is extremely cumbersome and error prone, if what you have on the
grid is a listing of a folder's file then you should have previously bind
this grid with this data, using somethinig like Directory.GetFiles( )
If it's so then you could keep this array on session and in the postback
just get it back:

string[] FileArray;

if ( !IsPostBack )
{
FileArray = Directory.GetFiles( Request.PhysicalApplicationPath )
Session["FileArray"] = FileArray;

}
else
{
FileArray = string[] Session["FileArray"];
}


Hope this help,
 
True,
but we also want to use the generic grid to upload XML files,
allow the user to make changes on the grid (Add, Edit, Del)
and then save back the grid values into the XML.

So, I was looking at creating my own XML with 2 for loops (Columns & Rows)

At that point I wonder if I could get a dataset off the grid and save it as
XML.


Filippo.



Ignacio Machin ( .NET/ C# MVP ) said:
Hi Filippo,

The grid is intended to work as a view of a data backend ( like a dataset )
it's not intended as a datasource , it's possible to take a grid and build a
data collection with it, basically a collection or records ( you can view
this as a array or a table), you could create a dataset with a table that
contain the same number of columns that cells has a grid's row.

Now this is extremely cumbersome and error prone, if what you have on the
grid is a listing of a folder's file then you should have previously bind
this grid with this data, using somethinig like Directory.GetFiles( )
If it's so then you could keep this array on session and in the postback
just get it back:

string[] FileArray;

if ( !IsPostBack )
{
FileArray = Directory.GetFiles( Request.PhysicalApplicationPath )
Session["FileArray"] = FileArray;

}
else
{
FileArray = string[] Session["FileArray"];
}


Hope this help,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation



Filippo Pandiani said:
I have a grid that shows the file list from a folder.
On the postback, how do I get a Dataset from this grid?


Thanks,
Filippo.
 
Hi ,


The datasource of the grid is not important, the issue is that the grid is
mean only as a display of the data, that is kept somewhere else ( dataset,
xml, etc )

Maybe with one example this become clearer.
If the user edit one row, this generate a postback, in the postback you set
the DataGrid.EditItemIndex = e.Item.ItemIndex and then call
DataGrid.DataBind() to rebind the grid.

In the Update command of the grid you should get the edited values, update
the datasource and set the EditItemIndex = -1 and rebind the grid again, as
you can see you rebind the grid anytime that the datasource changed or how
that data is viewed is modified ( as put a row in edit mode ).

Hope this help,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

Filippo Pandiani said:
True,
but we also want to use the generic grid to upload XML files,
allow the user to make changes on the grid (Add, Edit, Del)
and then save back the grid values into the XML.

So, I was looking at creating my own XML with 2 for loops (Columns & Rows)

At that point I wonder if I could get a dataset off the grid and save it as
XML.


Filippo.



"Ignacio Machin ( .NET/ C# MVP )" <ignacio.machin AT dot.state.fl.us> wrote
in message news:%[email protected]...
Hi Filippo,

The grid is intended to work as a view of a data backend ( like a dataset )
it's not intended as a datasource , it's possible to take a grid and
build
a
data collection with it, basically a collection or records ( you can view
this as a array or a table), you could create a dataset with a table that
contain the same number of columns that cells has a grid's row.

Now this is extremely cumbersome and error prone, if what you have on the
grid is a listing of a folder's file then you should have previously bind
this grid with this data, using somethinig like Directory.GetFiles( )
If it's so then you could keep this array on session and in the postback
just get it back:

string[] FileArray;

if ( !IsPostBack )
{
FileArray = Directory.GetFiles( Request.PhysicalApplicationPath )
Session["FileArray"] = FileArray;

}
else
{
FileArray = string[] Session["FileArray"];
}


Hope this help,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation



Filippo Pandiani said:
I have a grid that shows the file list from a folder.
On the postback, how do I get a Dataset from this grid?


Thanks,
Filippo.
 
Hummm I see.
OK let me give you a better idea of what I am doing.

I have a tree that shows 6 different XML names.
On click of a node I load the XML on a datagrid.

Then I let the user make changes (ADD-EDIT_DEL) and never post back until
the user clicks the SAVE button.

At that point, I get the MyDataGrid updated values and
....and save to XML.

I read somewhere that I could convert my grid back into a DataSet
and then (off course) save the DataSet as XML.

Even if I use the Edit-Add-Del events, I still don't understand how I can
update the datasource. What does the datasource, at that time looks like?

Is it a DataSet, or is it an XML in memory... ?

Hizzzzz !!!

<hehe>

Filippo.





Ignacio Machin ( .NET/ C# MVP ) said:
Hi ,


The datasource of the grid is not important, the issue is that the grid is
mean only as a display of the data, that is kept somewhere else ( dataset,
xml, etc )

Maybe with one example this become clearer.
If the user edit one row, this generate a postback, in the postback you set
the DataGrid.EditItemIndex = e.Item.ItemIndex and then call
DataGrid.DataBind() to rebind the grid.

In the Update command of the grid you should get the edited values, update
the datasource and set the EditItemIndex = -1 and rebind the grid again, as
you can see you rebind the grid anytime that the datasource changed or how
that data is viewed is modified ( as put a row in edit mode ).

Hope this help,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

Filippo Pandiani said:
True,
but we also want to use the generic grid to upload XML files,
allow the user to make changes on the grid (Add, Edit, Del)
and then save back the grid values into the XML.

So, I was looking at creating my own XML with 2 for loops (Columns & Rows)

At that point I wonder if I could get a dataset off the grid and save it as
XML.


Filippo.



"Ignacio Machin ( .NET/ C# MVP )" <ignacio.machin AT dot.state.fl.us> wrote
in message news:%[email protected]...
Hi Filippo,

The grid is intended to work as a view of a data backend ( like a dataset )
it's not intended as a datasource , it's possible to take a grid and
build
a
data collection with it, basically a collection or records ( you can view
this as a array or a table), you could create a dataset with a table that
contain the same number of columns that cells has a grid's row.

Now this is extremely cumbersome and error prone, if what you have on the
grid is a listing of a folder's file then you should have previously bind
this grid with this data, using somethinig like Directory.GetFiles( )
If it's so then you could keep this array on session and in the postback
just get it back:

string[] FileArray;

if ( !IsPostBack )
{
FileArray = Directory.GetFiles( Request.PhysicalApplicationPath )
Session["FileArray"] = FileArray;

}
else
{
FileArray = string[] Session["FileArray"];
}


Hope this help,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation



I have a grid that shows the file list from a folder.
On the postback, how do I get a Dataset from this grid?


Thanks,
Filippo.
 
Back
Top