Quote:using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Data; using System.Data.SqlClient; using System.Configuration; using CrystalDecisions.CrystalReports.Engine; using CrystalDecisions.Shared;//for ReportDocument namespace WebApplicationTraining.Reports { public partial class ProjectReportWithPara : System.Web.UI.Page { SqlConnection Con = new SqlConnection(ConfigurationManager.ConnectionStrings["MainDB"].ConnectionString); SqlCommand cmd = new SqlCommand(); #region Help Method private void ProjectDataBind() { DataSet ds = new DataSet(); SqlDataAdapter adapter = new SqlDataAdapter(cmd); try { Con.Open(); cmd.CommandText = "sp_Project_SelectAll"; cmd.CommandType = CommandType.StoredProcedure; cmd.Connection = Con; adapter.Fill(ds, "tbl_Project"); } catch (Exception ex) { throw new Exception(ex.Message); } finally { cmd.Dispose(); if (Con.State != ConnectionState.Closed) Con.Close(); } //DataTable dt = controller.SelectAll(); cboFromProject.DataTextField = "Project"; cboFromProject.DataValueField = "ProjectID"; cboFromProject.DataSource = ds.Tables[0]; cboFromProject.DataBind(); } private void ToProjectDataBind() { DataSet ds = new DataSet(); SqlDataAdapter adapter = new SqlDataAdapter(cmd); try { Con.Open(); cmd.CommandText = "sp_Project_SelectAll"; cmd.CommandType = CommandType.StoredProcedure; cmd.Connection = Con; adapter.Fill(ds, "tbl_Project"); } catch (Exception ex) { throw new Exception(ex.Message); } finally { cmd.Dispose(); if (Con.State != ConnectionState.Closed) Con.Close(); } //DataTable dtable = controller.SelectAll(); cboToProject.DataTextField = "Project"; cboToProject.DataValueField = "ProjectID"; cboToProject.DataSource = ds.Tables[0];//dtable; cboToProject.DataBind(); } public DataSet getFromTOProjects(int fproject, int toproject) { //string sqlCon = ConfigurationManager.AppSettings["MainDB"].ToString(); DataSet ds = null; SqlDataAdapter adapter; try { Con.Open(); cmd.CommandText = "sp_projectReport_ByProject"; cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add(new SqlParameter("@fproject", fproject)); cmd.Parameters.Add(new SqlParameter("@toproject", toproject)); cmd.Connection = Con; ds = new DataSet(); adapter = new SqlDataAdapter(cmd); adapter.Fill(ds, "tbl_Project"); //adapter.Fill(ds); } catch (Exception ex) { throw new Exception(ex.Message); } finally { cmd.Dispose(); if (Con.State != ConnectionState.Closed) Con.Close(); } return ds; } #endregion protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { ProjectDataBind(); ToProjectDataBind(); } if (IsPostBack) { try { CrystalReportViewer2.ReportSource = (ReportDocument)Session["Report"]; //CrystalReportViewer2.RefreshReport(); write this code,will prompt //CrystalReportViewer2.DataBind(); } catch (Exception ex) { // throw; } } } protected void btnPreview_Click(object sender, EventArgs e) { ReportDocument rptDoc = new ReportDocument(); DataSet ds = new DataSet(); DataTable dtable = new DataTable(); dtable.TableName = "tbl_Project"; ds = getFromTOProjects(Convert.ToInt32(cboFromProject.SelectedValue), Convert.ToInt32(cboToProject.SelectedValue)); dtable = ds.Tables[0]; rptDoc.Load(Server.MapPath("~\\Reports\\ProjectReportWithPara.rpt")); rptDoc.SetDataSource(dtable); rptDoc.SetParameterValue("ReportTitle", "Project Report By Project"); rptDoc.SetParameterValue("FromProject", cboFromProject.SelectedItem.Text); rptDoc.SetParameterValue("ToProject", cboToProject.SelectedItem.Text); Session["Report"] = rptDoc; CrystalReportViewer2.ReportSource = rptDoc; // can print and export but prompt already set parameters //CrystalReportViewer2.ReuseParameterValuesOnRefresh = false; //CrystalReportViewer2.DataBind(); //CrystalReportViewer2.ReportSource = rptDoc.Clone(); //CrystalReportViewer2.RefreshReport(); } } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)