views:

137

answers:

2

Hi,

I am using a gridview with sqldatasource. How to get back the datasource in the codebehind as a datatable?

+2  A: 
rahul
i have tried this option. but it returns null
Geetha
it returns null
Geetha
A: 

Use System.Data.DataTable dt = (System.Data.DataTable)gview.DataSource; if you are binding a DataTable.

You can even extract the DataTable out of DataSet if you are binding DataSet as System.Data.DataTable dt2 = (System.Data.DataTable)((System.Data.DataSet)gvValidDA.DataSource).Tables[0]; you will have to check the index of your table or table name as you prefer.

Happy coding.

Ravia