首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > .NET >

ReportViewer控件绑定rpt水晶报表解决思路

2013-11-20 
ReportViewer控件绑定rpt水晶报表做了一个rpt格式的水晶报表,想在窗体上显示。网上看了下。要配合ReportView

ReportViewer控件绑定rpt水晶报表
做了一个rpt格式的水晶报表,想在窗体上显示。网上看了下。要配合ReportViewer控件才能使用。
后台代码怎么写来绑定rpt水晶报表?
给个简单的例子?
[解决办法]
http://blog.csdn.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传给模板,无需数据库,下载可运行。


http://hasibulhaque.com/index.php/2011/crystal-report-asp-net-mvc/
[解决办法]
挺好的,我也学到了一招。

热点排行