【问题标题】:crystal reports using parameters使用参数的水晶报表
【发布时间】:2011-05-23 20:05:06
【问题描述】:

我是第一次使用水晶报表。我写了如下代码

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

我在下拉列表中获取值,但是,

现在我的问题是,一旦我从下拉列表中选择了一个值,我想要报告该值。 怎么做.....

请帮我解决我的问题。

【问题讨论】:

    标签: c# asp.net crystal-reports-2008


    【解决方案1】:

    尝试使用参数的索引号:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多