Quang Le Duy

Quang Le Duy

  • NA
  • 13
  • 45.9k

Passing Parameter from DropDownList into Crystal Report

Oct 7 2010 12:12 PM
Hi! I've had problem about passing parameter from DropdownList into CrystalReport , i don't know  how to fix it! I'm really need some advices that could help me
My Problem:
i have 2 table CatBook and Product
here is my code:
//using Webservice ,but it doesn't matter,i just need to pass parameter to crystalreport
// ser in an instance of method of webservice
private localhost.Service ser = new localhost.Service();
    protected void Page_Load(object sender, EventArgs e)
    {
        if(!Page.IsPostBack)
        {
          
            getdatatodroplist();
        }
    }
   //this method to load data from CatBook table
    public void getdatatodroplist()
    {
        string table = "CatBook";
        string condition = "1";
        string var = "1";
        string select = "CatBook.*";
        string chuoi = "@Table;" + table + ";@Condition;" + condition + ";@Var;" + var + ";@select;" + select + ";";
        DataSet ds = new DataSet();
        ds = ser.getdata("sp_getdata", chuoi); //sp_getdata is procedure
        DropDownList1.DataSource = ds.Tables[0];
        DropDownList1.DataTextField = "Cat_Name";
        DropDownList1.DataValueField = "Cat_Id";
        DropDownList1.DataBind();
        DropDownList1.SelectedIndex = 0;
       
   
    }
    protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    {
       //Here is my problem-----------------------------------
        ReportDocument report = new ReportDocument();
        report.Load(Server.MapPath("CrystalReport6.rpt"));
        report.SetDatabaseLogon("sa", "", "Graeme", "SachAmazon");

        CrystalReportViewer1.SelectionFormula = "{CatBook.Cat_Id}=" + DropDownList1.SelectedValue;
        CrystalReportViewer1.ReportSource = report;
        getdatatodroplist();
      
           
    }
thanks in advance!

Answers (5)