Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I export a GridView.DataSource to a datatable or dataset?

How can I export GridView.DataSource to datatable or dataset?

like image 853
ALEXALEXIYEV Avatar asked Apr 24 '09 13:04

ALEXALEXIYEV


People also ask

How to set GridView DataSource to DataTable?

GridView grd = new GridView(); grd. DataSource = SqlDataSource1; grd. DataBind(); DataTable dt = new DataTable(); dt =(DataTable)grd.

How to convert DataGridView into DataTable in c#?

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.


2 Answers

Assuming your DataSource is of type DataTable, you can just do this:

myGridView.DataSource as DataTable 
like image 182
Kon Avatar answered Oct 02 '22 17:10

Kon


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.

like image 32
Marco Vinicio Gomez G. Avatar answered Oct 02 '22 15:10

Marco Vinicio Gomez G.