我正在使用以下代码在页面加载事件中绑定Crystal Reports。
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;
}
正确绑定并显示报告。我在按钮单击事件中将过滤器应用于报表,当我单击搜索按钮时,报表显示的是同一组数据。它没有显示过滤后的值。按钮单击事件代码如下:
using (MilitrymessEntities entity = new MilitrymessEntities())
{
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;
}
你对这个问题有什么看法吗?
答案 0 :(得分:0)
您需要检查页面加载事件的帖子。如下所示,
if(!page.IsPostback())
{
using (MilitrymessEntities entity = new MilitrymessEntities())
{
BarporderReports barporpt = new BarporderReports();
barporpt.Refresh();
barporpt.SetDataSource(query);
crviewer_barpurchaseorder.RefreshReport();
crviewer_barpurchaseorder.ReportSource = barporpt;
}
}
此外,您应该在刷新之前设置报告和数据源,
BarporderReports barporpt = new BarporderReports();
barporpt.SetDataSource(query);
barporpt.Refresh();
crviewer_barpurchaseorder.ReportSource = barporpt;
crviewer_barpurchaseorder.RefreshReport();