首先,确保GridView中已经成功更新数据。
在ASP.NET页面中添加报表控件,如Crystal Reports或RDLC报表。
在页面代码中添加以下代码:
//定义数据源 DataTable dt = new DataTable(); dt = getData(); //获取数据
//绑定报表 ReportDocument rpt = new ReportDocument(); rpt.Load(Server.MapPath("Report.rpt"));
rpt.SetDataSource(dt);
//将报表输出到页面 CrystalReportViewer1.ReportSource = rpt;
在代码中定义getData()方法,并在其中编写查询数据库的代码以获取数据。
在GridView中添加Update事件,可以使用以下代码:
protected void GridView1_Update(object sender, GridViewUpdateEventArgs e) { //更新数据库中的数据
//重新绑定GridView
GridView1.DataBind();
//刷新报表
DataTable dt = new DataTable();
dt = getData();
ReportDocument rpt = new ReportDocument();
rpt.Load(Server.MapPath("Report.rpt"));
rpt.SetDataSource(dt);
CrystalReportViewer1.ReportSource = rpt;
}