I am using a gridview with sqldatasource. How to get back the datasource in the codebehind as a datatable?
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.