簡體   English   中英

如何將代碼隱藏數據集綁定到RDLC?

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

我有一個包含dropdownlist和reportviewer的頁面,並且我使用dropdownlist.selectValue作為我的參數來查詢並構建我想要的數據表

我的問題是:如何將代碼隱藏的數據表綁定到RDLC,以及如何在reportviewer上顯示

進行大量谷歌搜索並找到壁櫥結果https://blogs.msdn.microsoft.com/sqlforum/2011/04/27/walkthrough-assign-dataset-dynamically-created-in-code-to-your-local-報告與-的ReportViewer /

只有一個錯誤

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

我想這正是rdlc綁定我的編碼數據表的地方。

但我找不到DataTable1BindingSource

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

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

期望rdlc綁定我自己的編碼數據表

最后,我通過將編碼數據集重命名為DataSet.xsd中的相同名稱來進行計算。 不僅是架構,還需要使代碼中的數據集名稱與xsd文件中的名稱匹配。

例如:創建一個DataSet1.xsd包含一個名為DataTable1(默認名稱)的數據表

在你的代碼是

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

如果您聲明的其他名稱與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