Datagrid -> DataSet

  • Thread starter Thread starter Mark
  • Start date Start date
M

Mark

Hi, does anyone know how I can simply get the dataset that is bound to a
DataGrid?

Something like...

DataSet dsDataSet = DataGrid1.Tables[0]...........

Thanks
Mark
 
H all, I did this;
DataSet oDs = (DataSet)dataGrid1.DataSource;

it seems a little suspect to have to do a manual cast, there must be a
better way surely?
 
Hi,

No , no really the DataSource is of type Object , IIRC therefore you have
to cast it.
It should be wrapped in a try/catch as it may rise exception.

In general it's a bad practice do this kind of construction, it's better if
you keep a reference to the original datasource.

cheers,

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

Mark said:
H all, I did this;
DataSet oDs = (DataSet)dataGrid1.DataSource;

it seems a little suspect to have to do a manual cast, there must be a
better way surely?

Mark said:
Hi, does anyone know how I can simply get the dataset that is bound to a
DataGrid?

Something like...

DataSet dsDataSet = DataGrid1.Tables[0]...........

Thanks
Mark
 
You need to cast it to a Dataset because a Datagrid can be populated
from datasources other than Datasets also, like Datatables, Arrays,
ArrayLists, Collection classes etc.

Sijin Joseph
http://www.indiangeek.net
http://weblogs.asp.net/sjoseph


H all, I did this;
DataSet oDs = (DataSet)dataGrid1.DataSource;

it seems a little suspect to have to do a manual cast, there must be a
better way surely?

Hi, does anyone know how I can simply get the dataset that is bound to a
DataGrid?

Something like...

DataSet dsDataSet = DataGrid1.Tables[0]...........

Thanks
Mark
 
Back
Top