ReportViewer控件的使用
前台:
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager runat="server">
</asp:ScriptManager>
<div>
<rsweb:ReportViewer ID="ReportViewer1" runat="server">
</rsweb:ReportViewer>
</div>
</form>
</body>
</html>
后台:
protected void Page_Load(object sender, EventArgs e)
{
DataTable dt = new DataTable();
dt.Columns.Add(new DataColumn("row1", typeof(string)));
dt.Columns.Add(new DataColumn("row2", typeof(string)));
for (int i = 0; i < 6; i++)
{
DataRow dr = dt.NewRow();
dr[0] = "a";
dr[1] = "b";
dt.Rows.Add(dr);
}
//ReportViewer1.LocalReport.ReportPath = Application.StartupPath + "\\Report1.rdlc";
//指定数据集,数据集名称后为表,不是DataSet类型的数据集
ReportViewer1.LocalReport.ReportPath = AppDomain.CurrentDomain.BaseDirectory + "\\Report1.rdlc";
this.ReportViewer1.LocalReport.DataSources.Clear();
this.ReportViewer1.LocalReport.DataSources.Add(new Microsoft.Reporting.WebForms.ReportDataSource("mytable", dt));
//显示报表