Search code examples
c#gridviewsqldatasource

How to get the datasource of a gridview


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


Solution

  • Edited

    Use SqlDataSource.Select Method and assign it to a dataview

    DataView dv = (DataView)SqlDataSource1.Select(DataSourceSelectArguments.Empty);
    

    Then extract the datatable using

    DataTable dt =  (DataTable)dv.ToTable();