C# 如何在asp.net 3.5中使用自定义代码导出crystal报表
我只想导出水晶报告与多个选项,如PDF,EXCEL,WORD。在这里,我将介绍如何实现此功能的u代码C# 如何在asp.net 3.5中使用自定义代码导出crystal报表,c#,asp.net,crystal-reports,C#,Asp.net,Crystal Reports,我只想导出水晶报告与多个选项,如PDF,EXCEL,WORD。在这里,我将介绍如何实现此功能的u代码 //Page Declaration Section protected string strQueryString; protected int intLastPage; protected int intCurPage; protected void Page_Init(object sender, System.EventArgs e) { s
//Page Declaration Section
protected string strQueryString;
protected int intLastPage;
protected int intCurPage;
protected void Page_Init(object sender, System.EventArgs e)
{
strQueryString = Request.QueryString.ToString();
Page.Title = strQueryString.Replace(".rpt", "");
if (!Page.IsPostBack)
{
//Do nothing
}
else if (Session[strQueryString] != null)
{
CrystalReportViewer1.ReportSource = Session[strQueryString];
}
}
protected void lbut_print_Click(object sender, EventArgs e)
{
MPE.Show();
......
reportdocument = new ReportDocument();
SqlConnectionStringBuilder SConn = new SqlConnectionStringBuilder(conString);
reportdocument.Load(Server.MapPath(@"~/Admin/PostHistoryReport.rpt"));
reportdocument.SetDataSource(myDataSet);
reportdocument.DataSourceConnections[0].SetConnection(SConn.DataSource, SConn.InitialCatalog, SConn.UserID, SConn.Password);
Session[strQueryString] = reportdocument;
//Session["SessDoc"] = reportdocument;
CrystalReportViewer1.ReportSource = reportdocument;
}
protected void ImageButton7_Click(object sender, ImageClickEventArgs e)
{
if (DDL_ExportOption.SelectedItem.Value != "-1")
{
ReportDocument crystalReport = (ReportDocument)Session[strQueryString]; // creating object of crystal report
switch (DDL_ExportOption.SelectedItem.Value.ToString())
{
case "1":
crystalReport.ExportToHttpResponse(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat, Response, true, "PostRecordDetails");
break;
case "2":
crystalReport.ExportToHttpResponse(CrystalDecisions.Shared.ExportFormatType.ExcelRecord, Response, true, "PostRecordDetails");
break;
case "3":
crystalReport.ExportToHttpResponse(CrystalDecisions.Shared.ExportFormatType.WordForWindows, Response, true, "PostRecordDetails");
break;
}
}
}
我是如何得到这个会话[strQueryString]
的,但它不会以文件的形式输出
请帮助我……在本课程中,最好是尽可能简单地为报表而不是报表类提供数据。我不能这样做。我在lbut\u print\u Click方法中完成了很多代码,在所有过程之后,我将这些数据传递给Session[strQueryString]。现在,每当我想要从crystal report中获取数据时,我都可以访问它。