How can I export GridView.DataSource
to datatable or dataset?
GridView grd = new GridView(); grd. DataSource = SqlDataSource1; grd. DataBind(); DataTable dt = new DataTable(); dt =(DataTable)grd.
Converting DataGridView to DataTable When the Convert Button is clicked, first the Columns from the DataGridView are used to create a DataTable and then using a loop, data from each Row of DataGridView is inserted into the DataTable in Windows Forms (WinForms) Application using C# and VB.Net.
Assuming your DataSource is of type DataTable, you can just do this:
myGridView.DataSource as DataTable
You should convert first DataSource
in BindingSource
, look example
BindingSource bs = (BindingSource)dgrid.DataSource; // Se convierte el DataSource DataTable tCxC = (DataTable) bs.DataSource;
With the data of tCxC
you can do anything.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With