1.添加引用在Demo文件夹下面的FastReport.dll和FastReport.Web.dll
2.添加using FastReport;
using FastReport.Web;
3. 在Web页面上拖拉FastReport到页面,进入Design 视图进行设计
4。 为FastReport添加 WebReport1_StartReport事件
/// <summary>
/// 得到数据
/// </summary>
/// <returns></returns>
public DataSet getData()
{
string con = ConfigurationManager.ConnectionStrings["con"].ConnectionString;
SqlConnection connection = new SqlConnection(con);
SqlCommand command = new SqlCommand("Select * from Manager",connection);
SqlDataAdapter sda = new SqlDataAdapter(command);
DataSet ds=new DataSet();
DataTable managerData = new DataTable();
managerData.TableName = "Manager";
sda.Fill(managerData);
ds.Tables.Add(managerData);
DataTable payrecord = new DataTable();
payrecord.TableName = "PayRecord";
SqlCommand command1 = new SqlCommand("select * from PayRecord", connection);
SqlDataAdapter sda1 = new SqlDataAdapter(command1);
sda1.Fill(payrecord);
ds.Tables.Add(payrecord);
return ds;
}
protected void WebReport1_StartReport(object sender, EventArgs e)
{
FastReport.Report report = this.WebReport1.Report;
report.Load(Server.MapPath("\\ReportTemplate\\demo.frx"));//加载模板
DataSet ds=this.getData();
report.RegisterData(ds);//注册数据
}
5.为Table添加Table2_ManualBuild事件
private void Table2_ManualBuild(object sender, EventArgs e)
{
DataSourceBase source=Report.GetDataSource("Manager");
source.Init();
Table2.PrintRow(0);
Table2.PrintColumns();
while(source.HasMoreRows)
{
Table2.PrintRow(1);
Table2.PrintColumns();
source.Next();
}
}