数据集来RDLC报告动态绑定 [英] Dynamically binding of Dataset to RDLC Reports
问题描述
我想动态数据绑定到RDLC。如果我使用内联数据源中的ASPX文件(静态绑定)我可以查看报告。但是,如果我用下面的代码中,观众的报告不断出现中..形象。
我已经检查集名,如果我改变了数据集名称以ORDERS2,它显示我未提供所需的数据订单。所以,我想补充的形式在GridView和测试我的数据集。该数据集包含的数据,并与GridView控件显示良好。
问题是只与报告,我不能动态数据绑定到的ReportViewer。请帮帮我。谢谢你。
保护无效的Page_Load(对象发件人,EventArgs五)
{
的DataSet DS = GetDataSet( );
ReportDataSource RDS =新ReportDataSource(订单,ds.Tables [0]);
ReportViewer1.LocalReport.DataSources.Clear();
ReportViewer1.LocalReport.DataSources.Add(RDS);
ReportViewer1.LocalReport.Refresh();
GridView1.DataSource = DS;
GridView1.DataBind();
}
私人数据集getDataSet()返回
{
VAR conString = ConfigurationManager.ConnectionStrings [dotnetConnectionString];
串strConnString = conString.ConnectionString;
SqlConnection的康恩=新的SqlConnection(strConnString);
conn.Open();
字符串SQL =SELECT * FROM订单;
SqlDataAdapter的广告=新SqlDataAdapter的(SQL,conn);在
的DataSet DS =新的DataSet();
ad.Fill(DS);
返回DS;
}
ASPX代码如下:
<表ID =form1的=服务器>
< DIV>
< ASP:的ScriptManager ID =ScriptManager1=服务器>
< / ASP:ScriptManager的>
< rsweb:ID的ReportViewer =ReportViewer1=服务器HEIGHT =600px的WIDTH =800像素>
< LocalReport ReportPath =Reports\Report.rdlc>
<数据源>
< rsweb:ReportDataSource />
< /数据源>
< / LocalReport>
< / rsweb:&的ReportViewer GT;
< ASP:GridView控件ID =GridView1=服务器>
< / ASP:GridView的>
< / DIV>
< /表及GT;
我已经解决了我的问题。
问题是你需要添加下面的IsPostBack包装你的代码。
如果( !Page.IsPostBack)
{
//你的绑定代码在这里
}
I would like to bind the dynamically dataset to the rdlc. I can view the report if I use inline DataSource in ASPX file (static binding). However, if I use the following codes, the Report viewer keeps showing "Loading.." Image.
I have already check the dataset name and if I changed the dataset name to "Orders2", it shows me that required dataset "Orders" is not provided. So, I add the GridView on the form and test my DataSet. The dataset contains data and showing well with the GridView.
The problem is only with the Report and I could not bind data dynamically to the ReportViewer. Please help me. Thanks.
protected void Page_Load(object sender, EventArgs e)
{
DataSet ds = GetDataSet();
ReportDataSource rds = new ReportDataSource("Orders", ds.Tables[0]);
ReportViewer1.LocalReport.DataSources.Clear();
ReportViewer1.LocalReport.DataSources.Add(rds);
ReportViewer1.LocalReport.Refresh();
GridView1.DataSource = ds;
GridView1.DataBind();
}
private DataSet GetDataSet()
{
var conString = ConfigurationManager.ConnectionStrings["dotnetConnectionString"];
string strConnString = conString.ConnectionString;
SqlConnection conn = new SqlConnection(strConnString);
conn.Open();
string sql = "Select * FROM Orders";
SqlDataAdapter ad = new SqlDataAdapter(sql, conn);
DataSet ds = new DataSet();
ad.Fill(ds);
return ds;
}
ASPX codes are as below:
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<rsweb:ReportViewer ID="ReportViewer1" runat="server" Height="600px" Width="800px">
<LocalReport ReportPath="Reports\Report.rdlc">
<DataSources>
<rsweb:ReportDataSource />
</DataSources>
</LocalReport>
</rsweb:ReportViewer>
<asp:GridView ID="GridView1" runat="server">
</asp:GridView>
</div>
</form>
I have already solved my problem.
The problem is you need to add your codes under IsPostBack wrapping.
if (!Page.IsPostBack)
{
//your binding codes here
}
这篇关于数据集来RDLC报告动态绑定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!