ReportViewer with Subreport - Error processing subrelation

1
protected void Page_Load(object sender, EventArgs e)
{
    if (IsPostBack == true)
    {

        Sipom.DataSets.RelatorioTableAdapters.TodasTabelasTableAdapter Tabela = new
        Sipom.DataSets.RelatorioTableAdapters.TodasTabelasTableAdapter();
        Sipom.DataSets.Relatorio.TodasTabelasDataTable data = Tabela.GetDataTodos();

        ReportViewer1.LocalReport.Refresh();

        ReportViewer1.LocalReport.SubreportProcessing += new SubreportProcessingEventHandler(SetSubDataSource);

    } 

    public void SetSubDataSource(object remetente, SubreportProcessingEventArgs e)
    {

        Sipom.DataSets.RelatorioTableAdapters.TodasTabelasTableAdapter Tabela = new Sipom.DataSets.RelatorioTableAdapters.TodasTabelasTableAdapter();
        Sipom.DataSets.Relatorio.TodasTabelasDataTable data = Tabela.GetDataTodos();
        ReportDataSource RDS1 = new ReportDataSource("DSRespostas", (System.Data.DataTable)data);
        ReportViewer1.LocalReport.DataSources.Add(RDS1); }

With this code I'm trying to process the subreport but the error appears in the following line: ReportViewer1.LocalReport.DataSources.Add(RDS1);

ERROR:

  An exception of type 'System.InvalidOperationException' occurred in Microsoft.ReportViewer.WebForms.dll but was not handled in user code

     

Additional information: The viewer control object is in read-only mode

Can someone help me? I can not solve this problem. What I want is to load the main report with the subreport using tableadpater .

    
asked by anonymous 29.10.2015 / 01:05

1 answer

0

Opa,

In your method SetSubDataSource method try adding the DataSource using the "e" you received as a parameter, for example, instead of doing:

ReportViewer1.LocalReport.DataSources.Add(RDS1);

Try changing to:

e.DataSources.Add(RDS1);

If it works, mark the answer as valid. Thanks!

    
31.10.2015 / 12:09