Export datatable from gridview to Local report in a Panel RRS feed

  • Question

  • User-1701433212 posted

    There is a datatable displayed in a gridview that needs to be exported. How can that most simply be done thru a Local report in a Panel.

    Please provide detailed instructions with code and examples. Thanks.

    Monday, September 11, 2017 5:55 PM

All replies

  • User347430248 posted

    Hi ASPBabe,

    retrieve the data source from grid view.

    BindingSource bs = (BindingSource)GridView1.DataSource;//You should first convert DataSourse into Binding Sourse
    DataTable dt = (DataTable) bs.DataSource; //Get GridView data source to Data table

    bind ReportViewer to DataTable.

    ReportViewer ReportViewer1 = new ReportViewer(); //Your ReportViewer Control
    ReportDataSource rds = new ReportDataSource("DataSet1_Customers_DataTable1",dt); // ReportViewerDataSource : ReportViewer is to be bind to this DataSource
    ReportViewer1.LocalReport.DataSources.Clear(); // Clear the Previous DataSource of ReportViewer
    ReportViewer1.LocalReport.DataSources.Add(rds); //bind ReportViewer1 to the new datasource(Which you wish)
    ReportViewer1.LocalReport.Refresh(); // Refresh the ReportViewer Control, ReportViewer1 in this case



    Tuesday, September 12, 2017 1:19 AM