可以';t在报表查看器中切换报表

本文关键字:报表 可以 | 更新日期: 2023-09-27 18:26:28

我在aspx上定义了这样的报表视图。

<form id="form1" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>
    <div style="margin-left:auto;margin-right:auto;width:100%">
        <%--<asp:ScriptManager ID="ScriptManager1" runat="server">--%>
            <rsweb:ReportViewer ID="ReportViewer1" runat="server" Width="1024px" 
                Font-Names="Verdana" Font-Size="8pt" InteractiveDeviceInfos="(Collection)" 
                WaitMessageFont-Names="Verdana" WaitMessageFont-Size="14pt" 
            Height="768px">
                <LocalReport ReportPath="Reports'Gestion.rdlc">
                    <DataSources>
                        <rsweb:ReportDataSource DataSourceId="ObjectDataSource1" Name="Prueba" />
                    </DataSources>
                </LocalReport>
            </rsweb:ReportViewer>
            <asp:ObjectDataSource ID="ObjectDataSource2" runat="server" 
            SelectMethod="obtenerGestionesPorTipificacion" 
            TypeName="SodexoSAT.Reports.DataSets.GestionesDataSet">
                <SelectParameters>
                    <asp:Parameter Name="gestion" Type="String" />
                </SelectParameters>
        </asp:ObjectDataSource>
        <asp:ObjectDataSource ID="ObjectDataSource1" runat="server" 
            SelectMethod="obtenerTodasGestiones" 
            TypeName="SodexoSAT.Reports.DataSets.GestionesDataSet">
        </asp:ObjectDataSource>
<%--            </asp:ScriptManager>--%>
    </div>
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" 
    style="margin-top: 47px" Text="Button" />
</form>

所以当我点击按钮时,我可以像这样更改报告

 ReportViewer1.Reset();
        ReportViewer1.LocalReport.ReportPath = @"Reports'GestionPorTipificacion.rdlc";
        ReportDataSource rds = new ReportDataSource();
        rds.DataSourceId = "ObjectDataSource2";
        ReportViewer1.LocalReport.DataSources.Clear();
        ReportViewer1.LocalReport.DataSources.Add(rds);
        ReportViewer1.LocalReport.Refresh();

它抛出这个错误

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

我做错了什么,因为我更改了事件中的数据源。我需要设置更多参数吗??

可以';t在报表查看器中切换报表

    <rsweb:ReportViewer ID="ReportViewer1" runat="server" Width="1024px" 
            Font-Names="Verdana" Font-Size="8pt" InteractiveDeviceInfos="(Collection)" 
            WaitMessageFont-Names="Verdana" WaitMessageFont-Size="14pt" 
        Height="768px">
            <LocalReport ReportPath="Reports'Gestion.rdlc">
                <DataSources>
                    <rsweb:ReportDataSource DataSourceId="ObjectDataSource1" Name="Prueba" />
                </DataSources>
            </LocalReport>
        </rsweb:ReportViewer>
        <asp:ObjectDataSource ID="ObjectDataSource1" runat="server" 
        SelectMethod="obtenerTodasGestiones" 
        TypeName="SodexoSAT.Reports.DataSets.GestionesDataSet">
    </asp:ObjectDataSource>
    <asp:ObjectDataSource ID="ObjectDataSource2" runat="server" 
        SelectMethod="obtenerGestionesPorTipificacion" 
        TypeName="SodexoSAT.Reports.DataSets.GestionesDataSet">
            <SelectParameters>
                <asp:Parameter Name="gestion" Type="String" />
            </SelectParameters>
    </asp:ObjectDataSource>

按钮点击事件应为

    ReportViewer1.Reset();
    ReportViewer1.LocalReport.DataSources.Add(new ReportDataSource("ur_2ndDatasetName", "ObjectDataSource2"));
    ReportViewer1.LocalReport.ReportPath = @"Reports'GestionPorTipificacion.rdlc";
    ReportViewer1.LocalReport.Refresh();