Click here to Skip to main content
15,886,137 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How to store Gridview data into Datatable

my code is:
C#
DataTable dtt=new DataTable();
dtt.Merge(gridview2.DataSource);
Posted
Updated 11-Feb-13 18:30pm
v2
Comments
vinodkumarnie 12-Feb-13 1:20am    
Are you binding gridview using Sqldatasource..?

Data Source type of GridView and DataTable is different. You need to convert it like this.

C#
BindingSource source = (BindingSource)gridView1.DataSource;
DataTable dt = (DataTable)source.DataSource;
 
Share this answer
 
its very simple i will show u a sample method u just tweak it according to your needs

C#
string str = "select pcode,fyyear,date,salary,ta,contigency,nrc,institcharges,others from monthly";
        SqlDataAdapter adp = new SqlDataAdapter(str, con);
        DataTable dt = new DataTable();
        adp.Fill(dt);
        GridView1.DataSource = dt;
        GridView1.DataBind();
 
Share this answer
 
Comments
[no name] 14-Feb-13 21:39pm    
He didn't want to bind GridView data. He asks for getting gridview data in a data table

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900