简体   繁体   English

如何将代码隐藏数据集绑定到RDLC?

[英]How can I bind code-behind dataset to RDLC?

I have a page which contains a dropdownlist and reportviewer, and I use dropdownlist.selectValue as my parameter to query, and build a datatable I want 我有一个包含dropdownlist和reportviewer的页面,并且我使用dropdownlist.selectValue作为我的参数来查询并构建我想要的数据表

My question is: How to bind the code-behind datatable to RDLC and how to show on reportviewer 我的问题是:如何将代码隐藏的数据表绑定到RDLC,以及如何在reportviewer上显示

Do a lot of googling and find the closet result https://blogs.msdn.microsoft.com/sqlforum/2011/04/27/walkthrough-assign-dataset-dynamically-created-in-code-to-your-local-report-with-reportviewer/ 进行大量谷歌搜索并找到壁橱结果https://blogs.msdn.microsoft.com/sqlforum/2011/04/27/walkthrough-assign-dataset-dynamically-created-in-code-to-your-local-报告与-的ReportViewer /

Only one error 只有一个错误

this.DataTable1BindingSource.DataSource = ds;
this.reportViewer1.RefreshReport();

I guess this exactly is where rdlc bind my coded datatable. 我想这正是rdlc绑定我的编码数据表的地方。

But I can't find DataTable1BindingSource 但我找不到DataTable1BindingSource

aspx ASPX

<asp:ScriptManager runat="server"></asp:ScriptManager> 
<rsweb:ReportViewer ID="ReportViewer1" runat="server" >
<LocalReport ReportPath="Report1.rdlc">
    <DataSources>
        <rsweb:ReportDataSource DataSourceId="ObjectDataSource1" Name="DataSet1" />
    </DataSources>
</LocalReport>
</rsweb:ReportViewer>
<asp:ObjectDataSource ID="ObjectDataSource1" runat="server" TypeName="DataSet1TableAdapters."></asp:ObjectDataSource>

cs CS

protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{  
code dataset and datatable here
}

Expect rdlc bind my own coded datatable 期望rdlc绑定我自己的编码数据表

Finally I worked out by making my coded dataset rename to the same name in the DataSet.xsd. 最后,我通过将编码数据集重命名为DataSet.xsd中的相同名称来进行计算。 Not only the schema, You need to make the dataset name in your code match with the name in xsd file. 不仅是架构,还需要使代码中的数据集名称与xsd文件中的名称匹配。

For example: Create a DataSet1.xsd contains a datatable named DataTable1(default name) 例如:创建一个DataSet1.xsd包含一个名为DataTable1(默认名称)的数据表

and in your code is 在你的代码是

DataSet DataSet1 = new DataSet("something");
DataTable DataTable1 = DataSet1.Tables.Add("something");

If you declare another name differ from the name defined in xsd, you will get an error on ReportViewer 如果您声明的其他名称与xsd中定义的名称不同,则会在ReportViewer上收到错误消息

A data source instance has not been supplied for the data source 'DataSet1'.

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM