【问题标题】:RDLC get ObjectDataSourceSelectMethod programmaticallyRDLC 以编程方式获取 ObjectDataSourceSelectMethod
【发布时间】:2018-10-10 12:30:15
【问题描述】:

我的应用程序中有一个嵌入式 RDLC 报告。

我正在使用localReport.GetDataSourceNames()获取RDLC中列出的数据源,但我还需要知道数据源的ObjectDataSourceSelectMethod

有没有办法以编程方式获取它?

更新 - 更多细节

该项目是一个 WPF 项目,我的 RDLC 都在一个“Web 项目”中以使用对象数据源,然后我引用该程序集并将我的嵌入式报告加载到流中:

     Assembly.Load("FleetManagement.Resources")
                .GetManifestResourceStream(string.Format("{0}{1}",
                                            "FleetManagement.Resources.Reports.",
                                            "FleetList.rdlc"));

然后我使用以下方法获取数据源名称:

    private string DataSourceName 
    { 
        get
        {
            var ass = Assembly.Load("FleetManagement.Resources");
            var rpt = new LocalReport();

            using (var stream = ass.GetManifestResourceStream(string.Format("{0}{1}", "FleetManagement.Resources.Reports.", "FleetList.rdlc")))
            {
                if (stream != null)
                    using (TextReader rdr = new StreamReader(stream))
                    {
                        rpt.LoadReportDefinition(rdr);
                        return rpt.GetDataSourceNames().FirstOrDefault();
                    }
            }
            return null;
        }
    }

现在我想做的是从该报告中获取ObjectDataSourceSelectMethod,类似于我获取DataSetName的方式

【问题讨论】:

    标签: c# wpf rdlc


    【解决方案1】:

    如果您使用的是ObjectDataSource,我想您的应用程序位于 ASP.NET 中。

    使用.GetDataSourceNames获得的名字可以得到DataSourceId

    Dim strDataSourceId as String = YourReportViewer.LocalReport.DataSources("NameObtainedByGetDataSourceNames").DataSourceId
    

    在 ASP.NET 中,您可以使用它在您的 Page 中找到对应的 ObjectDataSource;请注意,您使用Master 页面需要两个FindControl

    Dim strSelectMethod as String = CType(CType(Me.Master.FindControl("cphPage"), ContentPlaceHolder).FindControl(strDataSourceId), ObjectDataSource).SelectMethod
    

    【讨论】:

    • 请看我更新的问题,我没有使用 asp.net
    • 哇!这是一个完全不同的问题。你知道web项目的结构吗? ObjectDataSources 是嵌入在 aspx 页面中的吗?
    【解决方案2】:

    当你定义报告时,如果你这样做;

    <rs:ReportViewer ID="TestrptViewer" runat="server"...>
    <LocalReport ReportPath="myreport.rdlc">
        <DataSources>
            <rs:ReportDataSource DataSourceId="ObjectDataSource1" Name="FleetsReport" />
        </DataSources>
    </LocalReport>
    </rs:ReportViewer>
    
    <asp:ObjectDataSource ID="ObjectDataSource1" runat="server" SelectMethod="GetFleets" TypeName="DatasetType">
    </asp:ObjectDataSource>
    

    然后我想你可以提取一个 ObjectDataSource 类型的 ReportDataSource,然后获取 SelectMethod。我自己没有测试过。

    【讨论】:

    • 我没有使用 asp.net
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-11-12
    • 2016-09-16
    • 2012-09-12
    • 2013-09-26
    相关资源
    最近更新 更多