Search code examples
asp.netvisual-studio-2010report-viewer2010

asp.net ReportViewer - forcing a vertical scrollbar with SizeToReportContent=true


In VS10 is there a way to keep SizeToReportContent=true and force a vertical scrollbar? I have a DDL that allows the user to pick a report, which sets the DataSource for a ReportViewer. SizeToReportContent seems to be the only way to dynamically control the width of the report to align with the width of the ReportViewer. The page contains a display area with a height smaller than the reports. If the ReportViewer had a vertical scrollbar then the report would meet the display area constraints.

I have tried all kinds of combinations of style formatting and size changes to the .rdlc with no luck of forcing a scrollbar while SizeToReportContent=true.

Both the width and height properties of the ReportViewer are overridden, but from which property of the .rdlc?

The report is being processed locally, but I do not think that makes a difference.

TIA!


Solution

  • I hope this helps someone...

    Brute forcing the ReportViewer to generate required page dimensions.

    Set SizeToReport=false. Appended desired width of each report to the name of the .rdlc value separated by a "|". In the run report method split the selected value to get the .rdlc name and its width. This means physically determining the width of each report to be hard coded with the report name - [weak!].

    code:

    ddl in report .ascx [actually populated from the db, but I wanted to show data]

    <asp:DropDownList ID="reportDropDownList" runat="server" AutoPostBack="True" OnSelectedIndexChanged="RunReport">
        <asp:ListItem Selected="True" Value="0">-- Select Report --</asp:ListItem>
        <asp:ListItem Value="RVSum.rdlc|504" >RV Purchased Sum</asp:ListItem>
        <asp:ListItem Value="ZeroPricePurchasesView.rdlc|550">Zero Price Purchases</asp:ListItem>
        ...
    </asp:DropDownList>
    

    run report method:

    protected void RunReport(object sender, EventArgs e)
    {
        ObjectDataSource source = new ObjectDataSource("WC.DataAccess.DAO.ReportsDAO", "GetAllReports");
        string path = "RDLC" + "\\";
        string ddlValue = "";
    
    
        if (reportDropDownList.SelectedIndex != 0)
        {
            ddlValue = reportDropDownList.SelectedValue.ToString();
            string[] ddlSplit = ddlValue.Split('|');  //split ddl selected value
            path = path + ddlSplit[0];  //.rdlc name
            reportViewer.LocalReport.DataSources.Clear();
            reportViewer.LocalReport.ReportPath = path;
            reportViewer.LocalReport.DataSources.Add(new ReportDataSource("DataSet1", source));
    
            reportViewer.AsyncRendering = false;
            reportViewer.SizeToReportContent = false;
            reportViewer.ShowZoomControl = false;
            reportViewer.Height = 400;  // default value but exactly what is needed
    
            reportViewer.Width = Convert.ToInt32(ddlSplit[1]);  // desired report width
            reportViewer.DataBind();
    
        }
        else  /* default clear viewer */
        {
            reportDropDownList.SelectedIndex = 0;
            reportViewer.LocalReport.DataSources.Clear();
            reportViewer.Reset();
        }
    }
    

    I do not like this type of programming, but until MS provides a better report viewer this will do.

    I am still interested in some suggestions - moving on for now...