How can I export GridView.DataSource to datatable or dataset?
A:
Assuming your DataSource is of type DataTable, you can just do this:
myGridView.DataSource as DataTable
Kon
2009-04-24 13:21:04
Thanks you are ok...
Phsika
2009-04-24 13:25:59
Then how about you **accept** the answer?!
Michael
2010-09-03 08:10:26
+3
A:
http://www.vbforums.com/showthread.php?t=474895
//If DataSource of GridView1 is a DataTable
DataTable dt = (DataTable)GridView1.DataSource;
//If DataSource of GridView1 is a DataView
DataView dv = (DataView)GridView1.DataSource;
TheTXI
2009-04-24 13:21:50
A:
Personally I would go with:
DateTable tbl = Gridview1.DataSource as DataTable;
This would allow you to test for null as this results in either DataTable object or null. Casting it as a datable using (DataTable)Gridview1.Datasource would cause a crashing error in case the datasource is actually a DataSet or even some kind of collection.
Supporting Dcoumentation: MSDN Documentation on "as"
Tacoman667
2009-04-24 13:32:22