Crystal Report Show in Web With ParameterField

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;

namespace test
{
 /// <summary>
 /// drss 的摘要说明。
 /// </summary>
 public class drss : System.Web.UI.Page
 {
  protected System.Web.UI.WebControls.DropDownList ddlRegin;
  protected System.Web.UI.WebControls.Button btn;
  protected System.Web.UI.WebControls.TextBox txtDate;
  protected CrystalDecisions.Web.CrystalReportViewer crvDrss;
 
  private void getlist()
  {
   crvDrss.ReportSource = @"d:\Reports\Daily Region Sales Summary.rpt";

   if(!Page.IsPostBack)
   {
    ParameterField pf = crvDrss.ParameterFieldInfo["Region_Name"];
    foreach(ParameterDiscreteValue pdv in pf.DefaultValues)
    {
     ddlRegin.Items.Add(pdv.Value.ToString());
    }
   }

   ParameterFields paramFields = new ParameterFields ();
   ParameterField paramField = new ParameterField ();
   ParameterDiscreteValue discreteVal = new ParameterDiscreteValue ();
   ParameterRangeValue rangeVal = new ParameterRangeValue ();

   paramField.ParameterFieldName = "Business_Date";
   discreteVal.Value = txtDate.Text;
   paramField.CurrentValues.Add (discreteVal);
   paramFields.Add (paramField);
   
   paramField = new ParameterField ();
   discreteVal = new ParameterDiscreteValue ();
   paramField.ParameterFieldName = "Region_Name";
   if(ddlRegin.SelectedItem.Text ==  "")
   {
    discreteVal.Value = "shanghai";
   }
   else
   {
    discreteVal.Value = ddlRegin.SelectedItem.Text;
   }
   paramField.CurrentValues.Add (discreteVal);
   paramFields.Add (paramField);

   crvDrss.ParameterFieldInfo = paramFields;
   crvDrss.DisplayGroupTree = false;
   crvDrss.DisplayToolbar = false;
  }

  private void Page_Load(object sender, System.EventArgs e)
  {
   if(!Page.IsPostBack)
   {
    txtDate.Text = DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd");
    getlist();
   }
  }

  #region Web 窗体设计器生成的代码
  override protected void OnInit(EventArgs e)
  {
   //
   // CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
   //
   InitializeComponent();
   base.OnInit(e);
  }
  
  /// <summary>
  /// 设计器支持所需的方法 - 不要使用代码编辑器修改
  /// 此方法的内容。
  /// </summary>
  private void InitializeComponent()
  {   
   this.btn.Click += new System.EventHandler(this.Button1_Click);
   this.Load += new System.EventHandler(this.Page_Load);

  }
  #endregion

  private void Button1_Click(object sender, System.EventArgs e)
  {
   getlist();
  }
 }
}

你可能感兴趣的:(parameter)