我在jquery中調用了這個靜態web方法,並使用jquery填充表格 數據成功顯示在表格中。在web表單頁面中有一個下拉式選擇器和兩個日期選擇器(從date &到date)根據這些值的選擇數據顯示在表格中現在我想創建水晶報表的時候我點擊導出按鈕,然後是表格數據,下拉值&日期選擇器值將在報告在水晶報告中調用會話
我存儲在會話和呼叫DT希望在水晶報表打電話,我在水晶報表中添加的CrystalReportViewer
我有網靜態的WebMethod即
顯示[WebMethod]
public static string search_data(DateTime fromdate, DateTime todate, string region)
{
try
{
string result = "";
Ts1 td = new T1();
DateTime frDate = new DateTime(fromdate.Year, fromdate.Month, fromdate.Day, 0, 0, 0);
DateTime to_Date = new DateTime(todate.Year, todate.Month, todate.Day, 23, 59, 59);
List<griddataresult_Result> dq = td.griddataresult(frDate, to_Date, region).ToList();
DataTable dt = new DataTable();
dt.Columns.Add("ID", typeof(int));
dt.Columns.Add("OwnerName", typeof(string));
dt.Columns.Add("RegNo", typeof(string));
foreach (var c in dq)
{
dt.Rows.Add(c.ID, c.OwnerName, c.RegNo);
}
DataTable dtt= (DataTable)HttpContext.Current.Session["datagrid"];
result = DataSetToJSON(dt);
return result;
}
catch (Exception)
{
throw new Exception();
}
}
UPDATE
現在我在網頁表單
private void BindReport(ReportDocument crystalReport, DateTime fromdate, DateTime todate, string region)
{
TrackDataEntities1 t = new TrackDataEntities1();
crystalReport.Load(Server.MapPath("data.rpt"));
List<griddataresult_Result> dsc = t.griddataresult(fromdate, todate, region).ToList();
crystalReport.SetDataSource(dsc);
CrystalReportViewer1.ReportSource = crystalReport;
}
protected void Report_Click(object sender, EventArgs e)
{
DataTable dt = Session["datagrid"] as DataTable;
ReportDocument crystalReport = new ReportDocument();
//crystalReport.SetParameterValue("@fromdate", fromdate.Value);
//crystalReport.SetParameterValue("@todate", todate.Value);
//crystalReport.SetParameterValue("@region", regiondrop.SelectedValue);
BindReport(crystalReport,Convert.ToDateTime(fromdate.Value), Convert.ToDateTime(todate.Value), regiondrop.SelectedValue);
}
添加此當我在搜索點擊率則表數據顯示,然後我當我點擊報告按鈕表消失,空報告顯示
首先創建水晶報告,然後創建ReportDocument對象,通過給你添加水晶報告的路徑加載你的crstalreport並傳遞參數,如objreport.SetParameterValue(「@ frmdate」,frmdate);然後綁定crstalreportviewer.ReportSource = objreport; crstalreportviewer.Databind(); –
檢查更新請@ManishGoswami – user6628729
檢查更新@ManishGoswami – user6628729