0

我正在使用 rdlc 根据参数动态显示报告。第一次加载时一切正常。但是在我更改参数并再次加载后,即使数据表值已更改。rdlc 显示之前的结果。什么是我想念这里

  private void btnsearch_Click(object sender, EventArgs e)
        {
            reportLoad();
        }

        private void reportLoad()
        {

            var fromdate=txtfromdate.Text;
            var todate=txttodate.Text;
            var accontHead=ComboaccHead.SelectedValue;
            var drawbankid=combodraw.SelectedValue;
            var noabankid=combonoa.SelectedValue;
            var type=ComboType.SelectedIndex;
            spParamCollection.Clear();
            spParamCollection.Add(new SPParams { Name = "@fromdate", Value =Convert.ToDateTime(fromdate).ToString("yyyy-MM-dd") });
            spParamCollection.Add(new SPParams { Name = "@toDate", Value = Convert.ToDateTime(todate).ToString("yyyy-MM-dd") });
            spParamCollection.Add(new SPParams { Name = "@AccountHead", Value = Convert.ToInt32(accontHead) });
            spParamCollection.Add(new SPParams { Name = "@drawbankid", Value = Convert.ToInt32(drawbankid) });
            spParamCollection.Add(new SPParams { Name = "@noabankid", Value = Convert.ToDecimal(noabankid) });
            spParamCollection.Add(new SPParams { Name = "@type", Value = Convert.ToDecimal(type) });
            DataTable dt = db.getDataUsingSP("CashBookReport", spParamCollection);

            reportViewer1.Clear();

            ReportDataSource rds = new ReportDataSource();
          //  reportViewer1.LocalReport.Refresh();
            reportViewer1.Visible = true;
            rds.Value = dt;
            rds.Name = "KWADataSet";
            reportViewer1.LocalReport.DataSources.Add(rds);
           this.reportViewer1.RefreshReport();




        }
4

1 回答 1

0

btnsearch_Click 在 Page_Load 之后被触发,因此更改没有生效。

您需要将报表查看器reportViewer1 放在更新面板中,然后在reportLoad() 结束时对其进行更新

注意:我只是将 =Globals!ExecutionTime 表达式添加到 .rdlc 内的文本框中以测试刷新。

为简洁起见,我省略了参数。

<form id="form1" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server">
        </asp:ScriptManager>
    <div>

    <asp:UpdatePanel ID="updatepanel1" runat="server" UpdateMode="Conditional">
        <ContentTemplate>

        <rsweb:ReportViewer ID="reportViewer1" runat="server" Font-Names="Verdana" 
            Font-Size="8pt" InteractiveDeviceInfos="(Collection)" 
            WaitMessageFont-Names="Verdana" WaitMessageFont-Size="14pt">
            <LocalReport ReportPath="Report1.rdlc">
            </LocalReport>
        </rsweb:ReportViewer>

        <asp:Button runat="server" ID="btnSearch" Text="Search" onclick="btnSearch_Click" />

        </ContentTemplate>
    </asp:UpdatePanel>

    </div>
    </form>

然后在你的代码后面:

protected void btnSearch_Click(object sender, EventArgs e)
{
    reportLoad();
}

private void reportLoad()
{
    reportViewer1.LocalReport.DataSources.Clear();

    // your datasource assignment here

    reportViewer1.LocalReport.Refresh();

    updatepanel1.Update();
}
于 2014-10-21T11:02:27.967 回答