i am using rdlc to show a report dynamically based on the parameters.every thing works perfect on the first load .but after i change the parameter and load again even if the data table value is changed.rdlc is showing the previous result.what am i missing here
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();
}
The btnsearch_Click is being fired after Page_Load and therefore the changes are not taking effect.
You need to place the report viewer reportViewer1 within an update panel and then update it at the end of reportLoad()
Note: I simply added the =Globals!ExecutionTime expression to a text box within the .rdlc to test the refresh.
For brevity sake, I have omitted the parameters.
<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>
Then in your code behind:
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();
}