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));
//显示报表
this.ReportViewer1.LocalReport.Refresh();
}
为什么页面还是没有数据显示啊!求高手指导,或者给我个dome也行,小弟在这里谢过了!
[解决办法]
refer :
http://www.cnblogs.com/tearer/archive/2010/07/30/1788992.html
http://www.cnblogs.com/szytwo/archive/2012/04/12/2444145.html
[解决办法]
前台html
<rsweb:ReportViewer ID="ReportViewer1" runat="server">
<LocalReport ReportPath="Report1.rdlc">
<DataSources>
<rsweb:ReportDataSource DataSourceId="ObjectDataSource1" Name="mytable" />
</DataSources>
</LocalReport>
</rsweb:ReportViewer>