ReportViewer控件绑定rpt水晶报表解决思路
ReportViewer控件绑定rpt水晶报表
做了一个rpt格式的水晶报表,想在窗体上显示。网上看了下。要配合ReportViewer控件才能使用。
后台代码怎么写来绑定rpt水晶报表?
给个简单的例子?
------解决方案--------------------
http://blog.****.net/happy09li/article/details/6931959
------解决方案--------------------
是aspx页面吗?
在webform的pageload事件里生成reportDocument后,将其赋值给reportview控件的reportsource即可
------解决方案--------------------
这有个十分好的例子(mvc下的),你可以下下来看看,用的是PUSH模式,其在controller里生成一个list通过session传给模板,无需数据库,下载可运行。
做了一个rpt格式的水晶报表,想在窗体上显示。网上看了下。要配合ReportViewer控件才能使用。
后台代码怎么写来绑定rpt水晶报表?
给个简单的例子?
------解决方案--------------------
http://blog.****.net/happy09li/article/details/6931959
------解决方案--------------------
是aspx页面吗?
在webform的pageload事件里生成reportDocument后,将其赋值给reportview控件的reportsource即可
protected void Page_Load(object sender, EventArgs e)
{
try
{
bool isValid = true;
// 从session中取得报表的路径
string rptPath = System.Web.HttpContext.Current.Session["ReportPath"].ToString();
// 获取要注入到报表中的数据,我用的是PUSH模式
var rptSource = System.Web.HttpContext.Current.Session["ReportSource"];
// 检查报表是否存在
if (string.IsNullOrEmpty(rptPath)
------解决方案--------------------
!File.Exists (rptPath))
{
isValid = false;
}
//如果存在
if (isValid)
{
ReportDocument rd = new ReportDocument();
//加载报表模板
rd.Load(rptPath);
// 给模板灌数据
if (rptSource != null && rptSource.GetType().ToString() != "System.String")
rd.SetDataSource(rptSource);
//给view指定报表
CrystalReportViewer1.ReportSource = rd;
//释放session
Session["ReportPath"] = "";
Session["ReportSource"] = "";
}
else
{
Response.Write("<H2>目标报表:"+ rptPath+"不存在</H2>");
}
}
catch (Exception ex)
{
Response.Write(ex.ToString());
}
}
------解决方案--------------------
这有个十分好的例子(mvc下的),你可以下下来看看,用的是PUSH模式,其在controller里生成一个list通过session传给模板,无需数据库,下载可运行。