我正在尝试使用c#在asp.net中创建一个带有xml的xtrareport。我创建了xml并引用了xtrareport。我还在xtrareport设计上选择了数据源schmema和数据成员,并将字段放入标签。我也调试过数据集,它不是空的。但是我在我的报表页面上看不到数据。
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);`发布于 2015-11-04 16:22:40
我个人创建了一些扩展来加载和保存报告的xml布局。我使用win应用程序或其他应用程序创建它们,然后保存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;
}但首先,您必须使用报表设计器创建报表,将其加载到win应用程序中,使用GetXmlXtraReportLayout将布局保存到一个文件中。
https://stackoverflow.com/questions/33516107
复制相似问题