Click here to Skip to main content
15,887,344 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Everyone,

In my application I have one report viewer. The report viewer already binded with one [ReportVendor] report. While I'm clicking one button,I need to bind another report[ReportAssetList] with the report viewer. I have given my code below.



C#
private void button1_Click(object sender, EventArgs e)
        {
            reportViewer1.Reset();
            reportViewer1.ProcessingMode = ProcessingMode.Local;
            LocalReport localReport = reportViewer1.LocalReport;
            localReport.ReportPath = "ReportAssetList.rdlc";
            DataSet dataset = new DataSet("DataSetAssetList");

            GetAssetDetail(ref dataset);

            // Create a report data source for the sales order data
            ReportDataSource datasource = new ReportDataSource();
            datasource.Name = "assetsBindingSource";
            datasource.Value = dataset.Tables["Assets"];
            localReport.DataSources.Add(datasource);
            reportViewer1.Refresh();
            MessageBox.Show("Ok");
       }





public void GetAssetDetail(ref DataSet ds)
        {
            OleDbDataAdapter dataAdapter = new OleDbDataAdapter("SELECT Descriptn,                 AssetType, Location, Model, SerialNumber, Status, AssetCode, Dateofpurchase, WarrantyExpiry, Condition, Profile FROM Assets", con);
            dataAdapter.Fill(ds);
        }


Please help me with this..
Posted
Updated 2-Jun-15 1:18am
v2
Comments
ZurdoDev 2-Jun-15 14:31pm    
What exactly is your question?
Sarath kumar.N 3-Jun-15 1:10am    
I have one report viewer, but I have multiple reports. I need change the report as per the client input. For example client click for Assets detail. I need to bind the AssetDetail.rdlc report at runtime. I have written a code for that, but it's not working..
ZurdoDev 3-Jun-15 7:19am    
Change the report path. And what do you mean by it is not working?
Sarath kumar.N 3-Jun-15 7:25am    
Yeah I changed the path value from ReportVendor.rdlc to ReportAssetList.rdlc, But report viewer showing blank. It showing Nothing.
ZurdoDev 3-Jun-15 7:27am    
Is it inside an async update panel or are you somehow doing this with only a partial postback?

1 solution

At last I found the answer form Internet.

C#
OleDbDataAdapter dataAdapter = new OleDbDataAdapter("SELECT Descriptn, AssetType, Location, Model, SerialNumber, Status, AssetCode, Dateofpurchase, WarrantyExpiry, Condition, Profile FROM Assets", con);
            DataSet ds = new DataSet();
            dataAdapter.Fill(ds);
            reportViewer1.Reset();
            this.reportViewer1.LocalReport.DataSources.Clear();
            ReportDataSource reportDataSource = new ReportDataSource();
            reportDataSource.Value = ds.Tables[0];
            reportDataSource.Name = "DataSetAssetList";
            this.reportViewer1.LocalReport.DataSources.Add(reportDataSource);            
            this.reportViewer1.LocalReport.ReportEmbeddedResource = "AssestsManagementSystem.ReportAssetList.rdlc";            
            this.reportViewer1.RefreshReport();
 
Share this answer
 

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