您的位置:首页 > 其它

ReportViewer动态加载RDLC报表文件

2008-09-16 10:14 197 查看
Ihaveareportviewercontrol.Iprogrammaticallysetthelocalreportpathbasedonadropdownonapage.Thisallowstheusertochoosewhichformat(RDLCfile)tousewhengeneratingthereport.
Thefirstrequest,thereportprocessesproperly,howeverifIchooseadifferentreportformat,theoldreportstillrenders.I'mdoinga.refreshforthereport...
ItriedturningoffViewstateforthereport,butitsaysthatViewstatemustbetruefortheReportViewercontrol.
IfI"reenter"thepageasnew(suchasbyclickingonmymenuitemforthatpage),itwillthenrunthefirstreporttypechosen.
I'mchangingthelocalreportpathsuchasReportViewer1.LocalReport.ReportPath="myreport1.rdlc"
or
ReportViewer1.LocalReport.ReportPath="myreport2.rdlc"

Solution1:

使用多个ReportViewer,每个ReportViewer显示不同的RDLC。根据用户的选择显示一个ReportViewer,隐藏其他的ReportViewer。就在页面中添加多个ReportViewer控件来对应多个rdlc文件,然后根据需要显示和隐藏部分ReportViewer控件。

Solution2:

BecausethereisnoReportViewer.Reset()inC#,thesolutionistocreateannewinstanceofthereport.ThetrickistoSwapoutthepreviousReportViewerwiththeNewReportViewer.

ControlCollectioncc=this.ReportViewer1.Parent.Controls;
//getindexofpreviousReportViewersowecanswapitout.
intprevIndex=cc.IndexOf(this.ReportViewer1);
//RemovepreviousReportViewer
cc.Remove(this.ReportViewer1);
//addnewinstanceofReportViewer.
ReportViewer1=newMicrosoft.Reporting.WebForms.ReportViewer();
//Resetreportproperties.
ReportViewer1.Height=Unit.Parse("100%");
ReportViewer1.Width=Unit.Parse("100%");
ReportViewer1.CssClass="table";
//AddthenewReportViewertothepreviousReportViewerlocation.
cc.AddAt(prevIndex,ReportViewer1);
//Clearoutanypreviousdatasources.
this.ReportViewer1.LocalReport.DataSources.Clear();
//Setreportmodeforlocalprocessing.
ReportViewer1.ProcessingMode=ProcessingMode.Local;
//Createanewreportdataset.
DataSetdataSet=newDataSet();
this.ReportViewer1.LocalReport.ReportPath=Server.MapPath("ReportPeopleMailingList.rdlc");
//Loaddataset.
try
{	//retrievedataset.
dataSet=(DataSet)Session["sessionDataSetCli"];	}
catch
{
return;
}
//Assignreportparameters.
Microsoft.Reporting.WebForms.ReportParameter[]parms=newMicrosoft.Reporting.WebForms.ReportParameter[1];
parms[0]=newMicrosoft.Reporting.WebForms.ReportParameter("title","Clients");
ReportViewer1.LocalReport.SetParameters(parms);
//LoadthedataSource.
ReportViewer1.LocalReport.DataSources.Add(newReportDataSource("DataSetPeople_adPeople",dataSet.Tables[0]));
//RefreshtheReportViewer
ReportViewer1.LocalReport.Refresh();
DimccAsControlCollection=ReportViewer1.Parent.Controls
DimprevIndexAsInteger=cc.IndexOf(ReportViewer1)
cc.Remove(ReportViewer1)
ReportViewer1=NewMicrosoft.Reporting.WebForms.ReportViewer()
ReportViewer1.Height=Unit.Parse("450px")
ReportViewer1.Width=Unit.Parse("980px")
cc.AddAt(prevIndex,ReportViewer1)
ReportViewer1.LocalReport.DataSources.Clear()
ReportViewer1.LocalReport.ReportPath=reportPath
ReportViewer1.LocalReport.DataSources.Add(datasource)
ReportViewer1.LocalReport.SetParameters(NewReportParameter(){.....})
ReportViewer1.LocalReport.Refresh()
Solution3:

Mustdoa

ReportViewer1.Reset()

ReportViewer1.LocalReport.Dispose()

first.Thensetyourreportpaths,thendoa
ReportViewer1.LocalReport.Refresh()
YoumusthaveVS2005SP1forthis.

From:

http://blog.csdn.net/qiujiahao/archive/2007/08/09/1733415.aspx

http://objectmix.com/dotnet/304568-change-report-path-reportviewer-control.html

http://66.129.67.4/t/1257010.aspx

http://forums.asp.net/t/1183208.aspx

http://social.msdn.microsoft.com/forums/en-US/vsreportcontrols/thread/c6524b68-bdfd-4f10-848f-355bc9445323/

http://www.tech-archive.net/Archive/DotNet/microsoft.public.dotnet.framework.aspnet.webcontrols/2008-07/msg00024.html
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: