C# 使用参数的crystal报告

C# 使用参数的crystal报告,c#,asp.net,crystal-reports-2008,C#,Asp.net,Crystal Reports 2008,我第一次使用crystal reports。我已经写了如下代码 public partial class _Default : System.Web.UI.Page { private ReportDocument report = new ReportDocument(); protected void Page_Load(object sender, EventArgs e) { report.Load(Server.MapPath("Crystal

我第一次使用crystal reports。我已经写了如下代码

public partial class _Default : System.Web.UI.Page 
{
    private ReportDocument report = new ReportDocument();
    protected void Page_Load(object sender, EventArgs e)
    {
        report.Load(Server.MapPath("CrystalReport1.rpt"));
        report.FileName = Server.MapPath("CrystalReport1.rpt");
        if (!Page.IsPostBack)
            {
                BindData();
            }
    }

protected override void OnUnload(EventArgs e)
{
    base.OnUnload(e);
    this.Unload+=new EventHandler(Page_Unload);
}

    public void Page_Unload(object sender, EventArgs e)
    {
        report.Clone();
        report.Dispose();
    }

private void BindData()
    {        
        Trusted_Connection=true";
        string connectionString = @"Data Source=WINSERVER;Initial Catalog=card;User       ID=sa;Password = db2admin";
        SqlConnection myConnection = new SqlConnection(connectionString);
        SqlDataAdapter ad = new SqlDataAdapter("SELECT name,address,idno FROM iffcar", myConnection);
        DataSet ds = new DataSet();
        ad.Fill(ds);
        DropDownList1.DataSource = ds;
        DropDownList1.DataTextField = "name";
        DropDownList1.DataValueField = "idno";
        DropDownList1.DataBind();
    }


protected void Btn_DisplayReport(object sender, EventArgs e)
    {

    int idno = Convert.ToInt32(DropDownList1.SelectedValue);
    report.SetParameterValue("idno", idno);
    CrystalReportViewer1.ReportSource = report;
    }
}
我在dropdownlist中获取值,但是,

现在我的问题是,一旦我从dropdownlist中选择了一个值,我就需要该值的报告。 如何做


请帮助我解决问题。

尝试使用参数的索引号:

protected void Btn_DisplayReport(object sender, EventArgs e)
{
   int idno = Convert.ToInt32(DropDownList1.SelectedValue);
   report.SetParameterValue(0, idno);
   CrystalReportViewer1.ReportSource = report;
}

尝试使用参数的索引号:

protected void Btn_DisplayReport(object sender, EventArgs e)
{
   int idno = Convert.ToInt32(DropDownList1.SelectedValue);
   report.SetParameterValue(0, idno);
   CrystalReportViewer1.ReportSource = report;
}