2015-11-04 61 views
0

我正嘗試在asp.net中使用c#在xml中創建一個xtrareport。我創建了xml並引用了xtrareport。我還選擇了xtrareport設計中的數據源schmema和數據成員,並將字段放入標籤。我也調試了數據集,它不是空的。但是我無法在報告頁面上看到數據。在asp.net中使用xml創建xtrareport

SqlConnection conn = new SqlConnection(@"blabla"); 
SqlCommand select = new SqlCommand(@"select * from table",conn); 

conn.Open(); 
SqlDataAdapter da = new SqlDataAdapter(select); 
DataSet ds = new DataSet(); 
da.Fill(ds); 

//ds.WriteXmlSchema(@"C:\dataset.xml"); 

XtraReport1 rpr = new XtraReport1(); 
rpr.DataSource = ds; 

rpr.PrintingSystem.SetCommandVisibility(PrintingSystemCommand.ClosePreview, DevExpress.XtraPrinting.CommandVisibility.None); 
rpr.CreateDocument(true);` 
+0

目前還不清楚你如何在你的asp.net頁面中使用你的報告。 – nempoBu4

回答

0

個人我創建擴展來加載和保存xml佈局的報告。 我創建它們與Windows應用程序或任何然後保存XML佈局:使用內存流

public static void RestoreFromXmlXtraReportLayout(this DevExpress.XtraReports.UI.XtraReport report, string xmlXtraReportLayout) 
{ 
    if (!string.IsNullOrEmpty(xmlXtraReportLayout)) 
    { 
     string fileName = System.IO.Path.GetTempPath() + Guid.NewGuid().ToString() + ".repx"; 
     System.IO.File.WriteAllText(fileName, xmlXtraReportLayout); 
     report.LoadLayout(fileName); 
     System.IO.File.Delete(fileName); 
    } 
} 

public static string GetXmlXtraReportLayout(this DevExpress.XtraReports.UI.XtraReport report) 
{ 
    string tmpFileName = System.IO.Path.GetTempPath() + Guid.NewGuid().ToString() + ".repx"; 
    report.SaveLayout(tmpFileName); 
    string xmlXtraReportLayout = System.IO.File.ReadAllText(tmpFileName); 
    System.IO.File.Delete(tmpFileName); 
    return xmlXtraReportLayout; 
} 

(但它不到風度工作得很好,有些數據會丟失,但你可以試試)

public static void RestoreLayoutFromNavigationItem(this DevExpress.XtraReports.UI.XtraReport report, string xmlXtraReportLayout) 
{ 
    if (!string.IsNullOrEmpty(xmlXtraReportLayout)) 
    { 
     using (Stream xmlStream = new System.IO.MemoryStream()) 
     { 
      XmlDocument xDoc = new XmlDocument(); 
      xDoc.LoadXml(xmlXtraReportLayout); 
      xDoc.Save(xmlStream); 
      xmlStream.Flush(); 
      xmlStream.Position = 0; 
      report.LoadLayoutFromXml(xmlStream); 
     } 
    } 
} 

和加載我用一個網頁,其中包含一個ASPxDocumentViewer報告:

<body> 
    <form id="formDocumentViewer" runat="server"> 
    <div> 
     <dx:ASPxDocumentViewer ID="mainDocumentViewer" runat="server"> 
    </dx:ASPxDocumentViewer> 
    </div> 
</form> 

在頁面加載:

protected void Page_Load(object sender, EventArgs e) 
{ 
    report.DataSource = "your data source"; 
    string xmlXtraReportLayout = "load it from the saved file"; 
    report.RestoreFromXmlXtraReportLayout(xmlXtraReportLayout); 
    this.mainDocumentViewer.SettingsSplitter.SidePaneVisible = false; 
    this.mainDocumentViewer.Report = report; 
} 

但首先你必須與報表設計器創建報表,在Windows應用程序加載它,使用GetXmlXtraReportLayout佈局保存到文件中。