Click here to Skip to main content
15,884,176 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am creating a site using ASP.net in Visual Studio 2010 and am having trouble with the Report Viewer control. I am trying to use one report viewer control and set the report name and data sets dynamically. I do not have an SSRS server available so all of this is internal to the application. I've tried two approaches, first on the ASP side:
ASP.NET
<% if (true)  // very simple test
       { %>
            <rsweb:ReportViewer ID="ReportViewer1" runat="server" 
                Font-Names="Verdana" 
                Font-Size="8pt" InteractiveDeviceInfos="(Collection)" 
                WaitMessageFont-Names="Verdana" WaitMessageFont-Size="14pt"
                Width="538px">
                <LocalReport ReportPath="AFR\SimpleTest.rdlc">
                    <DataSources>
                        <rsweb:ReportDataSource DataSourceId="dsTestInReport" 
                        Name="dsTest" />
                    </DataSources>
                </LocalReport>
            </rsweb:ReportViewer>
            <asp:SqlDataSource ID="dsTestInReport" runat="server" 
                ConnectionString="<%$ ConnectionStrings:Survey %>" 
                SelectCommand="SELECT * FROM [trefQuestionType]">
            </asp:SqlDataSource>
        <% }
       else
       { %>
            <rsweb:ReportViewer ID="ReportViewer2" runat="server" 
                Font-Names="Verdana" 
                Font-Size="8pt" InteractiveDeviceInfos="(Collection)" 
                WaitMessageFont-Names="Verdana" WaitMessageFont-Size="14pt"
                Width="538px">
                <LocalReport ReportPath="AFR\SimpleTest.rdlc">
                    <DataSources>
                        <rsweb:ReportDataSource DataSourceId="SqlDataSource1"
                                 Name="dsTest" />
                    </DataSources>
                </LocalReport>
            </rsweb:ReportViewer>
            <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
                ConnectionString="<%$ ConnectionStrings:Survey %>" 
                SelectCommand="SELECT * FROM [trefMinistry]"></asp:SqlDataSource>
        <%} %>

But all I got was a single report header with no data. If I comment out the If / else, I get two complete reports with data, but with the If / else included, I get nothing. Argh! So I decided to try Code Behind ...
C#
// open a connection, etc

// get the data into a table
SqlCommand _cmd = new SqlCommand("SELECT * FROM [trefMinistry]", _cn);
SqlDataAdapter _da = new SqlDataAdapter(_cmd);
System.Data.DataTable _tbl = new System.Data.DataTable();
_da.Fill(_tbl);

// attach the report and data to the Report Viewer control
ReportViewer1.LocalReport.Dispose();
ReportViewer1.LocalReport.ReportPath = @"AFR\SimpleTest.rdlc";
ReportViewer1.LocalReport.DataSources.Add(new
    Microsoft.Reporting.WebForms.ReportDataSource("dsTest", _tbl));

When I ran this, I got the error:
"An unexpected error occurred in Report Processing.
Value cannot be null. Parameter name: input"

Any pointers, tips, help or cash would be sincerely appreciated. (Sorry for the length, just trying to be complete.)
Posted
Updated 12-Jan-15 16:44pm
v3

Looks like you added a parameter in your report.
just remove that parameter.
 
Share this answer
 
I should have marked this as resolved. It did not have to do with a parameter, I had to prefix the code-behind with
if (!Page.IsPostBack)

I found this out by stepping through the code and having my break-point hit twice. Rookie mistake. Everything is working exceptionally well now. Thanks for your response.
 
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