水晶报表在浏览器里是显示的一页一页的你点了下一页他才转到下一页,我的数据是从查询里得出的数据,这样看来水晶报表的显示和DataGrid没有什么区别啊,究竟水晶报表有什么特殊的地方啊,他的数据源是DataSet,我要DataSet是从查询里生成的报表数据.
问题就是要动态的生成DataSet(这个很好办),然后设置报表的数据源,报表是用报表专家做的怎么动态的设置呢?
问题2就是打印,象word那么按页打印出来(但我看见的就是一个DataGrid那么的数据显示),怎么才能让他在IE中显示成一页一页的,请给出具体代码示例.
在水晶报表有经验的朋友帮个忙吧:
我的msn: [email protected]
问题就是要动态的生成DataSet(这个很好办),然后设置报表的数据源,报表是用报表专家做的怎么动态的设置呢?
问题2就是打印,象word那么按页打印出来(但我看见的就是一个DataGrid那么的数据显示),怎么才能让他在IE中显示成一页一页的,请给出具体代码示例.
在水晶报表有经验的朋友帮个忙吧:
我的msn: [email protected]
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using CrystalDecisions.Shared;
using CrystalDecisions.CrystalReports.Engine;
using System.Configuration;
using System.Data.SqlClient;namespace summarize.Crystal
{
/// <summary>
/// Summary description for pdf.
/// </summary>
public class pdf : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Button Button1;
public CrystalReport3 rptyi=new CrystalReport3();
private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
} #region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.Button1.Click += new System.EventHandler(this.Button1_Click);
this.Load += new System.EventHandler(this.Page_Load); }
#endregion private void Button1_Click(object sender, System.EventArgs e)
{
string Conn= ConfigurationSettings.AppSettings.Get("Con");
SqlConnection myconn=new SqlConnection(Conn);
string sql="select * from PartNumber";
DataSet ds=new DataSet();
SqlDataAdapter SDA=new SqlDataAdapter(sql,myconn);
try
{
SDA.Fill(ds,"PartNumber");//将表写入DataSet
}
catch
{
Response.Write("<script>history.back();alert('查询数据过多或数据问题!');</script>");
Response.End(); }
if (ds.Tables[0].Rows.Count>0)
{
rptyi.SetDataSource(ds.Tables[0]);
// 声明变量并获取导出选项。
ExportOptions exportOpts = new ExportOptions();
DiskFileDestinationOptions diskOpts = new DiskFileDestinationOptions();
exportOpts = rptyi.ExportOptions;
// 设置导出格式。
exportOpts.ExportFormatType = ExportFormatType.PortableDocFormat;
exportOpts.ExportDestinationType = ExportDestinationType.DiskFile; // 设置磁盘文件选项。
string pdfname="cha"+DateTime.Now.ToShortDateString()+"_"+DateTime.Now.ToLongTimeString().Replace(":","-")+"_"+DateTime.Now.Millisecond.ToString()+".pdf";
diskOpts.DiskFileName = Server.MapPath("PDF/"+pdfname);
exportOpts.DestinationOptions = diskOpts;
rptyi.Export();
rptyi.Dispose();
Response.Write("<script>window.open('pdf/"+pdfname+"');history.go(-1);</script>");
}
else
{
Response.Write("<script>history.back();alert('没有满足您查询条件的数据,请重新输入查询条件!');</script>");
Response.End();
}
}
}
}
数据源动态的设置可以参考下面:report=new MyReport();
Dataset1 dataSet=new Dataset1();
OleDbConnection conn=new OleDbConnection
("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=F:\\Visual Studio.net\\Crystal Reports\\Samples\\Database\\chs\\Xtreme.mdb");
OleDbDataAdapter oleAdapter=new OleDbDataAdapter("SELECT * FROM 订单",conn);
oleAdapter.Fill(dataSet,"订单");
OleDbDataAdapter oleDetailsAdapter=new OleDbDataAdapter("SELECT * FROM 订单细节",conn);
oleDetailsAdapter.Fill(dataSet,"定单细节");
report.SetDataSource(dataSet);
crystalReportViewer1.ReportSource=report;打印时连续的,也可以打印具体页。不需要另写代码