SAP Crystal Reports for VS2010 databindings, filter not applying
I am using the following code to bind Crystal Reports in page load event.
using (MilitrymessEntities entity = new MilitrymessEntities())
{
BarporderReports barporpt = new BarporderReports();
barporpt.Refresh();
barporpt.SetDataSource(query);
//barporpt.SetParameterValue("norows", 10);
crviewer_barpurchaseorder.RefreshReport();
crviewer_barpurchaseorder.ReportSource = barporpt;
}
It is binding properly and displaying the report. I applied filter to the report in the button click event, when I click the search button, the report is displaying the same set of data. It's not displaying the filtered value. The button click event code follows:
using (MilitrymessEntities entity = new MilitrymessEntiti开发者_如何学Goes())
{
DateTime dt1 = Convert.ToDateTime(txt_fromdate.Text);
DateTime dt2 = Convert.ToDateTime(txt_todate.Text);
string strdt1 = dt1.Date.ToString("MM/dd/yyyy");
string strdt2 = dt2.Date.ToString("MM/dd/yyyy");
dt1 = Convert.ToDateTime(strdt1);
dt2 = Convert.ToDateTime(strdt2);
var query = from data in entity.BarPurchaseOrders.AsEnumerable()
where (data.Date >= dt1) && (data.Date <= dt2) && data.ItemName == drp_itemname.SelectedItem.Text
select data;
BarporderReports barporpt = new BarporderReports();
barporpt.Refresh();
barporpt.SetDataSource(query);
crviewer_barpurchaseorder.RefreshReport();
crviewer_barpurchaseorder.ReportSource = barporpt;
}
Do you have any idea about this problem?
You need to be checking for a post back on page load event. Like below,
if(!page.IsPostback())
{
using (MilitrymessEntities entity = new MilitrymessEntities())
{
BarporderReports barporpt = new BarporderReports();
barporpt.Refresh();
barporpt.SetDataSource(query);
crviewer_barpurchaseorder.RefreshReport();
crviewer_barpurchaseorder.ReportSource = barporpt;
}
}
Also, you should be setting your report and data source before refreshing,
BarporderReports barporpt = new BarporderReports();
barporpt.SetDataSource(query);
barporpt.Refresh();
crviewer_barpurchaseorder.ReportSource = barporpt;
crviewer_barpurchaseorder.RefreshReport();
精彩评论