在asp.net中的usercontrol里面的Rdlc报告

时间:2014-03-25 11:38:15

标签: c# asp.net rdlc

我在usercontrol中有一个rdlc报告,我需要在页面上点击按钮时加载此usercontrol,但是当我在按钮上加载usercontrol时,单击reportviewer变为null。但是,如果我在没有按钮的情况下在页面上加载usercontrol,请单击其工作正常。

PageButton Click事件

protected void bGenerate_Click(object sender, EventArgs e)
        {

            UsrReport Usr = new UsrReport();
            Usr.LoadControl("~/UsrReport.ascx");
            Usr.ID = "rptdetails";
            PnlReport.Controls.Add(Usr);
        }

UserControl.ascx

  <rsweb:ReportViewer ID="rptViewer" runat="server" Width="100%" Height="600px" 
    Font-Names="Verdana" Font-Size="8pt" InteractiveDeviceInfos="(Collection)" 
    WaitMessageFont-Names="Verdana" WaitMessageFont-Size="14pt">
    </rsweb:ReportViewer>

Usercontrol PageLoad

 if (rptViewer != null)
    {
        rptViewer.Visible = true;
        rptViewer.Reset();

        rptViewer.LocalReport.ReportPath = Server.MapPath("~/Reports/rptLog.rdlc");
        var ReportData = DataConnection.GetDatalist("");
        ReportDataSource reportDSDetail = new ReportDataSource("DataList", 
ReportData);
        rptViewer.LocalReport.DataSources.Clear();
        rptViewer.LocalReport.DataSources.Add(reportDSDetail);

    }

0 个答案:

没有答案