我希望这可以帮助别人...
强制 ReportViewer 生成所需的页面尺寸。
设置 SizeToReport=false。将每个报告的所需宽度附加到由“|”分隔的 .rdlc 值的名称中。在运行报告方法中拆分所选值以获取 .rdlc 名称及其宽度。这意味着物理上确定要使用报告名称硬编码的每个报告的宽度 - [弱!]。
代码:
报告中的 ddl .ascx [实际上是从数据库中填充的,但我想显示数据]
<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>
运行报告方法:
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();
}
}
我不喜欢这种类型的编程,但在 MS 提供更好的报告查看器之前,我会这样做。
我仍然对一些建议感兴趣 - 现在继续......