Convert GridView To DataTable
-
Hi, I have a grid with 10K rows and i'm trying to convert it to datatable.
First Ex. DataTable dt = (DataTable)GridViewArgs.DataSource; Second Ex. DataView dataview = (DataView)GridViewArgs.DataSource; DataTable dt = dataview.Table.Clone();
In both ex. i got an empty datatable (the grid has values). Can someone please tell me what i'm doing wrong? -
Hi, I have a grid with 10K rows and i'm trying to convert it to datatable.
First Ex. DataTable dt = (DataTable)GridViewArgs.DataSource; Second Ex. DataView dataview = (DataView)GridViewArgs.DataSource; DataTable dt = dataview.Table.Clone();
In both ex. i got an empty datatable (the grid has values). Can someone please tell me what i'm doing wrong?treuveni wrote:
I have a grid with 10K rows
:doh: Which is not good design! Why 10 K Records in a grid? Does it really make any sense? It will hit your application performance very badly. Show only those data that are required. Use some filter to show less amount of data.
treuveni wrote:
DataTable dt = (DataTable)GridViewArgs.DataSource;
What is your Source of Gridview data ?
Cheers ! Abhijit Jana | My Blog | @Twitter | Disclaimer
-
Hi, I have a grid with 10K rows and i'm trying to convert it to datatable.
First Ex. DataTable dt = (DataTable)GridViewArgs.DataSource; Second Ex. DataView dataview = (DataView)GridViewArgs.DataSource; DataTable dt = dataview.Table.Clone();
In both ex. i got an empty datatable (the grid has values). Can someone please tell me what i'm doing wrong?First example should works. Second example:
DataView dataview = ((DataTable)GridViewArgs.DataSource).DefaultView;
I Love T-SQL "Don't torture yourself,let the life to do it for you." If my post helps you kindly save my time by voting my post. www.aktualiteti.com
-
Hi, I have a grid with 10K rows and i'm trying to convert it to datatable.
First Ex. DataTable dt = (DataTable)GridViewArgs.DataSource; Second Ex. DataView dataview = (DataView)GridViewArgs.DataSource; DataTable dt = dataview.Table.Clone();
In both ex. i got an empty datatable (the grid has values). Can someone please tell me what i'm doing wrong?If you are trying to retrieve the data after postback, datasource will return null unless you bind the data again. If your GridView ViewState is not disabled, you can access the data by iterating rows and columns like this:
foreach(GridViewRow row in grdRawData.Rows)
{
myData = row.Cells[ColNum].Text; // For BoundField only.//
}If you are using controls, say TextBox, in GridView Columns, you can fetch the data by using FindControl method.
TextBox txtName = (TextBox)grdRawData.Rows[rowNum].FindControl("IdOfTextBox"); // For BoundField only.//
myData = txtName.Text;Hope this will help.
Anurag Gandhi.
http://www.gandhisoft.com
Life is a computer program and every one is the programmer of his own life.
My latest article: Group GridView Data