using System; 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(这个很好办),然后设置报表的数据源,报表是用报表专家做的怎么动态的设置呢?
问题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();
}
}
}
}