简体   繁体   English

使用参数的水晶报表

[英]crystal reports using parameters

i am using crystal reports for the first time. 我是第一次使用水晶报表。 I have written code which is as follows 我写的代码如下

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;
    }
}

i am getting values in the dropdownlist but, 我在下拉列表中获取值,但是, 在此处输入图片说明

Now my problem is once i select a value from dropdownlist i want report of that value. 现在我的问题是,一旦我从下拉列表中选择一个值,我想报告该值。 how to do it..... 怎么做.....

please help me to solve my problem. 请帮助我解决我的问题。

Try using the index number of the parameter: 尝试使用参数的索引号:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM