11using System.Web.UI.HtmlControls;
12using Microsoft.ApplicationBlocks.Data;
13using Microsoft.Reporting.WebForms;
14
15public partial class ReportViewerLocalMode : System.Web.UI.Page
16{
17 public string thisConnectionString =
18 ConfigurationManager.ConnectionStrings[
19 "NorthwindConnectionString"].ConnectionString;
20
21 /**//*I used the following statement to show if you have multiple
22 input parameters, declare the parameter with the number
23 of parameters in your application, ex. New SqlParameter[4]; */
24
25 public SqlParameter[] SearchValue = new SqlParameter[1];
26
27 protected void RunReportButton_Click(object sender, EventArgs e)
28 {
29 //ReportViewer1.Visible is set to false in design mode
30 ReportViewer1.Visible = true;
31 SqlConnection thisConnection = new SqlConnection(thisConnectionString);
32 System.Data.DataSet thisDataSet = new System.Data.DataSet();
33 SearchValue[0] = new SqlParameter("@CategoryName",
34 DropDownList1.SelectedValue);
35
36 /**//* Put the stored procedure result into a dataset */
37 thisDataSet = SqlHelper.ExecuteDataset(thisConnection,
38 "ShowProductByCategory", SearchValue);
39
40 /**//*or thisDataSet = SqlHelper.ExecuteDataset(thisConnection,
41 "ShowProductByCategory", dropdownlist1.selectedvalue);
42 if you only have 1 input parameter */
43
44 /**//* Associate thisDataSet (now loaded with the stored
45 procedure result) with the ReportViewer datasource */
46 ReportDataSource datasource = new
47 ReportDataSource("DataSetProducts_ShowProductByCategory",
48 thisDataSet.Tables[0]);
49
50 ReportViewer1.LocalReport.DataSources.Clear();
51 ReportViewer1.LocalReport.DataSources.Add(datasource);
52 if (thisDataSet.Tables[0].Rows.Count == 0)
53 {
54 lblMessage.Text = "Sorry, no products under this category!";
55 }
56
57 ReportViewer1.LocalReport.Refresh();
58 }
59}</PRE>
第六步:运行报表
按F5键,单击”Run Report”按钮运行报表。
图六,运行报表
最后要确定ReportViewer被引入到网站中,并且要配置下web.config文件,它有可能是如下的格式:
<httpHandlers>
<add path="Reserved.ReportViewerWebControl.axd" verb="*"
type="Microsoft.Reporting.WebForms.HttpHandler,
Microsoft.ReportViewer.WebForms,
Version=8.0.0.0, Culture=neutral,
PublicKeyToken=?????????????"
validate="false" />
</httpHandlers>
当把有ReportViewer控件的网站项目部署到别的服务器的时候,你需要把C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\BootStrapper\Packages\ReportViewer\ReportViewer.exe这个文件拷贝出来,然后在目标服务器运行一下。
翻译心得:似乎做过的翻译中这个是最简单的了,不过可能也是作者说的比较简介明了。
学习心得:作者阐述了两种ReportViewer能接受的报表方式并且做了简单的分析。不过在实际项目中用Server Mode的可能会更多些吧,Local Mode做一些不是规模太大或者太复杂的报表还是可以的。
公司里有专门做RS的我知道,据说做就要做一周,运行的时候看编写的质量,十分钟是正常的,而超过三十分钟的话就可能需要考虑改算法了。听起来好恐怖,呵呵,不过,如果能用到楼下光电部门的报表需求的话,我想要比以前GridView to Excel的方式更舒服一些。
如果这个能研究明白的话打算做一个专门的入门视频讲解来帮助更多的人了解这个控件。
文章整理:西部数码--专业提供域名注册、虚拟主机服务
http://www.west263.com
以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢!




