2009-08-27 17 views
13

Dahili sayfalama olması beklenen bir aspx sayfasında Crystal Report Viewer denetimi var. Ben "Bir sonraki sayfa" düğmesini ilk kez tıkladığınızdaCrystal Reports Viewer geçmez sayfa 2

, ben sayfa 2 sayfa 1 hareket, ancak her zaman "Bir sonraki sayfa" sayfa 2.

+0

Post ReportViewer kod arkasında kullanışlı yardım almak için! –

cevap

22

sorun olabilir rapor reloads tıklayın Crystal Report Viewer denetiminin ReportSource olayını Page_Load olayı sırasında ayarlamadan kaynaklanır. Bu, her sayfa yükü ile sayfalama bilgilerinin üzerine yazılmasına neden olur, bu nedenle "geçerli sayfa", 2'de olması gerektiği zaman 1 olarak yeniden ayarlanır.

Kolay bir çözüm olarak, ayarlanan kodu taşıyabilirsiniz. ReportSource

+0

Çok teşekkür ederim! – Slovo

+0

page_ınit taşıma sorunu çözmek, ama şimdi onun rapor kaynağını kapatan bir sorun yaşıyorum. Bu yöntemleri çağırmak istiyorum report.Close(); report.Dispose(); Ancak bunları Page_Init sırasında arayamıyorum. Bağlantıları kapatmadan, kullanıcılar raporu bir süre kullandıktan sonra bu hatayı alıyorum: Crystal Reports Exception: Sistem yöneticiniz tarafından yapılandırılan maksimum rapor işleme işleri sınırına ulaşıldı – stillsmallvoice

+0

@stillsmallvoice Yerel yerine rapor kaynağı için bir alan kullanın değişken ve sayfanın içine atın. Dispose() 'geçersiz kılma. –

0

Page_Init içine ben visual studio 2008 öncesinde böyle bir sorun vardı, yüklemeden kristal (temel servis paketi 1 Crystal müdahale başka WebControl orada değilse, kontrol bende böyle bir sorun vardı sorunu

0

çözüldü geri arama sorunu raporları ? JavaScript? Emin değilim). Benim özel durumumda, Dart File Upload ve Crystal aynı sayfaya koyulduğunda iyi anlaşamadı.

4
if (!Page.IsPostBack) 
{ 
    //Write your Report display code 

    crystalRep.Load(Server.MapPath("DueFD.rpt")); 
    crystalRep.SetDatabaseLogon(DB_UId, DB_Pass, Serv_Name, DB_Name); 
    CrystalReportViewer1.ReportSource = crystalRep; 

    // session code 
    ReportDocument doc = (ReportDocument)Session["ReportDocument"]; 
    CrystalReportViewer1.ReportSource = doc; 
} 
else 
{ 
    ReportDocument doc = (ReportDocument)Session["ReportDocument"]; 
    CrystalReportViewer1.ReportSource = doc; 
} 
5

el Page_Init() için Page_Load içeriğini hareket

this.Init += new System.EventHandler(this.Page_Init). 

ile InitializeCompnent() içinde page_ınit() olay ve yukarı tel ekleyin.

PageInIt içinde if (!IsPostBack) koşulunu ekleyin.

protected void Page_Init(object sender, EventArgs e) { 

    if (!IsPostBack) 
    { 
     ReportDocument crystalReportDocument = new ReportDocumment(); 
     crystalReportDocument.SetDataSource(DataTableHere); 
     _reportViewer.ReportSource = crystalReportDocument; 
     Session["ReportDocument"] = crystalReportDocument; 
    } 
    else 
    { 
      ReportDocument doc = (ReportDocument)Session["ReportDocument"]; 
      _reportViewer.ReportSource = doc; 
    } 
} 
+0

Teşekkürler, en iyi cevap. – Ramunas

0

Tüm yükleme raporlarını Page_Load yerine Page_Init dosyasına koydum. Ve düzgün çalışıyor.

0

Benim için bu 13.0.1'den 13.0.10'a yükseltilene kadar gayet iyi çalıştı, bu yüzden açıkça bir şeyler değişti.

Yukarıdaki çözümü denedim, ancak rapor parametrelerini güncellemeye geri gönderdiğimiz ve sayfa parametrelerine rapor parametrelerini ayarlamazsanız, yenileme başarısız oluyor. Bu yüzden, bugün itibariyle sayfa yüklemesinde bir şey yapmadan çalışamıyorum.

Değişen param değerlerini denetlemek ve yalnızca değiştirildiyse raporu yenilemek için bir mantık eklemek zorunda kalacağımdan şüpheleniyorum.

1

page_ınit yerine Page_Load ait Ve raporu Rapor Kaynağı koyun Page_Load Ben Muhtemelen

Bana uyar
1

çalıştığını düşünüyorum parametreleri !!

ReportDocument rd = new ReportDocument(); 

     protected void Page_Load(object sender, EventArgs e) 
     {   
      string rptpath = WebConfigurationManager.AppSettings["ReportPath"].Replace("{TID}", Convert.ToString(Session["TID"])); 
      rd.Load(rptpath); 

      DataTable dtable = TemplateModel.LoadChequeData(Convert.ToString(Session["CID"])); 
      rd.SetDataSource(dtable);   
     } 

     protected void Page_Init(object sender, EventArgs e) 
     { 
      CrystalReportViewer1.ReportSource = rd; 
     } 
0

Paylaşmak için bazı yaklaşımlarım var. Crystal Reports oluşturmaya yardımcı olabilecek basit CR sarmalayıcıyı geliştirdim. Bu kodu olduğu gibi kullanın. Lütfen kodun herhangi bir bölümünü değiştirmek, değiştirmek için çekinmeyin. İndirme bağlantısı https://1drv.ms/u/s!AlTLBrnU_bLUiaoUxcxNiRCZRQjWng

Ve örnek, sarıcıyı, enter code here kimlik doğrulaması arabirimini uygulayan CR sarıcı sınıfını kullanarak nasıl kullanacağını gösterir.Page_Load olaylarda page_ınit rapor kaynağını ve rapor parametrelerini ayarlayın ve Page_Unload olay raporu belgesini imha edin.
İkinci yöntem statik sınıfını kullanır ve sonunda rapor belgesini imha, olanları rapor oluşturma. Rapor kaynağı oturum değişkenine kaydedilmelidir. Statik sınıfın kullanılması nedeniyle ikinci yöntemin yüksek trafikli web uygulamasında gerçekten uygun olmadığını lütfen unutmayın. İki kullanıcı aynı anda herhangi bir rapor çalıştırırsa, çarpışma gerçekleşir.

Yöntem 1

using System; 
using System.Linq; 
using CrystalDecisions.Shared; 
using System.Configuration; 
using System.Web.Configuration; 
using WebReports.Models.Helpers.CrystalReports; //Reference to CR wrapper 


namespace YourNamespace 
{ 
    public partial class ReportForm : System.Web.UI.Page 
    { 

     protected string _serverName; 
     protected string _databaseName; 
     protected string _schemaName; 
     protected string _userId; 
     protected string _userPassword; 
     protected bool _integratedSecurity; 
     protected string _databaseType; 
     //Wrapper Report Document 
     protected CReportDocument _reportDocument; 

     /// <summary> 
     /// Load report 
     /// </summary> 
     /// <param name="sender"></param> 
     /// <param name="e"></param> 
     protected void Page_Init(object sender, EventArgs e) 
     { 
      //Wrapper object 
      this._reportDocument = new CReportDocument(); 

      //These settings should be initialized from i.e. web.config in Page_PreInit 

      this._reportDocument.ServerName = this._serverName; 
      this._reportDocument.DatabaseName = String.Empty; 
      this._reportDocument.SchemaName = this._schemaName; 
      this._reportDocument.DatabaseType = CReportDatabaseType.ORACLE; 
      this._reportDocument.UserId = this._userId; 
      this._reportDocument.UserPassword = this._userPassword; 
      this._reportDocument.IntegratedSecurity = false; 


      //Get report name from query string. Define Your own method to get report name 
      var parReportName = Request.QueryString["reportname"]; 

      if (String.IsNullOrEmpty(parReportName)) 
      { 
       lblConfigError.Text = "Crystal Report name is not being provided."; 
       return; 
      } 

      //Set Report file 
      this._reportDocument.ReportFile = Server.MapPath("~/ReportFiles/") + parReportName; 
      //Set Report documant 
      this._reportDocument.SetReportDocument(); 
      //Get Report Document 
      crViewer.ReportSource = this._reportDocument.GetReportDocument(); 

     } 

     protected void Page_Load(object sender, EventArgs e) 
     { 

      CReportParameter reportParameter; 

      //Get parameters Your own method to provide report parameters 
      var parFimYear = RouteData.Values["par1"]; 
      var parFimCityCode = RouteData.Values["par2"]; 

      if (par1 == null || par2 == null) 
      { 
       lblConfigError.Text = "Crystal Report parameters are not being provided."; 
       return; 
      } 

      //Define Report Parameter 
      reportParameter = new CReportParameter(); 
      reportParameter.ParameterName = "@parYear"; 
      reportParameter.ParameterValue = parFimYear; 
      reportParameter.crParameterValueKind = ParameterValueKind.StringParameter; 
      _reportDocument.AddCReportParameter(reportParameter); 

      reportParameter = new CReportParameter(); 
      reportParameter.ParameterName = "@parCityCode"; 
      reportParameter.ParameterValue = parFimCityCode; 
      reportParameter.crParameterValueKind = ParameterValueKind.StringParameter; 
      _reportDocument.AddCReportParameter(reportParameter); 

      //Set report parameters 
      this._reportDocument.SetReportParameters(); 

     } 

     protected void Page_Unload(object sender, EventArgs e) 
     { 
      this._reportDocument.Dispose(); 
     } 

    } 
} 

Yöntem 2

using System; 
using System.Linq; 
using CrystalDecisions.Shared; 
using System.Configuration; 
using System.Web.Configuration; 
using CrystalDecisions.CrystalReports.Engine; 
using WebReports.Models.Helpers.CrystalReports; //Reference to CR wrapper 

namespace YourNamespace 
{ 
    public partial class ReportForm : System.Web.UI.Page 
    { 

     protected string _serverName; 
     protected string _databaseName; 
     protected string _schemaName; 
     protected string _userId; 
     protected string _userPassword; 
     protected bool _integratedSecurity; 
     protected string _databaseType; 

     /// <summary> 
     /// Load report 
     /// </summary> 
     /// <param name="sender"></param> 
     /// <param name="e"></param> 
     protected void Page_Init(object sender, EventArgs e) 
     { 
      CReportParameter reportParameter; 

      //These settings should be initialized from i.e. web.config in Page_PreInit 

      if (!IsPostBack) 
      { 
       if (this._databaseType == CReportDatabaseType.ORACLE.ToString()) 
       { 
        //static wrapper class 
        CReportDocumentManager.ServerName = this._serverName; 
        CReportDocumentManager.DatabaseName = String.Empty; 
        CReportDocumentManager.SchemaName = this._schemaName; 
        CReportDocumentManager.DatabaseType = CReportDatabaseType.ORACLE; 
        CReportDocumentManager.UserId = this._userId; 
        CReportDocumentManager.UserPassword = this._userPassword; 
        CReportDocumentManager.IntegratedSecurity = false; 

        //Get report name from query string. Define Your own method to get report name 
        var parReportName = Request.QueryString["reportname"]; 

        if (String.IsNullOrEmpty(parReportName)) 
        { 
         lblConfigError.Text = "Crystal Report name is not being provided."; 
         return; 
        } 
         //get par1. Your own method to provide report parameters. This is from MVC application 
         var par1 = RouteData.Values["par1"]; 
         //get par2 
         var par2 = RouteData.Values["par2"]; 

         if (par1 == null || par2 == null) 
         { 
          lblConfigError.Text = "Crystal Report parameters are not being provided."; 
          return; 
         } 

         reportParameter = new CReportParameter(); 
         reportParameter.ParameterName = "@parYear"; 
         reportParameter.ParameterValue = par1; 
         reportParameter.CReportParameterValueKind = ParameterValueKind.StringParameter; 
         CReportDocumentManager.AddCReportParameter(reportParameter); 

         reportParameter = new CReportParameter(); 
         reportParameter.ParameterName = "@parCityCode"; 
         reportParameter.ParameterValue = par2; 
         reportParameter.CReportParameterValueKind = ParameterValueKind.StringParameter; 
         CReportDocumentManager.AddCReportParameter(reportParameter); 



        CReportDocumentManager.ReportFile = Server.MapPath("~/ReportFiles/") + parReportName; 
        ReportDocument doc = CReportDocumentManager.GetCReportDocument(); 
        crViewer.ReportSource = doc; 
        Session[parReportName] = doc; 

       } 
      } 
      else 
      { 
       var parReportName = Request.QueryString["reportname"]; 
       ReportDocument doc = (ReportDocument)Session[parReportName]; 
       crViewer.ReportSource = doc; 

      }     
     } 

    } 
} 
İlgili konular