动态改变水晶报表分组

1.建立一个公式字段GroupName:

     在公式编辑器中 随便拖一个字段,设为{t_BuyOrder.BuyOrderDate} (当然是你自己表中的字段)

 

2.在报表中插入组时,选择刚才的建立的公式GroupName

 

 

3.在代码中动态控制报表的分组: //通过DropDownList控制

    swich(dropdownList......)

       {

 

        case "BuyOrderDate"://字段名

           report.DataDefinition.FormulaFields["GroupName"].Text = "{t_BuyOrder.BuyOrderDate}"; //这里也可是字段的组合

       case "State":

           report.DataDefinition.FormulaFields["GroupName"].Text = "{t_BuyOrder.State}";

          ...................

          

        }

 

 

 

以下是部分伪码,只求表达意义:

string sql = "Select * from t_BuyOrder"; string DBConfig_sql = @"Data Source=FCC-B1EA5171DD0/SQL2005;Initial Catalog=ERP_DB;User ID=sa;Password=411325;"; DataSet2 ds = new DataSet2(); SqlConnection sqlCon = new SqlConnection(DBConfig_sql); SqlCommand sqlCmd = new SqlCommand(sql, sqlCon); SqlDataAdapter sqlAd = new SqlDataAdapter(); sqlAd.SelectCommand = sqlCmd; sqlAd.Fill(ds, "t_BuyOrder"); ReportDocument ocr = new ReportDocument(); ocr.Load(Server.MapPath("DynamicGroup.rpt")); cr.SetDataSource(ds.Tables["t_BuyOrder"]); swich(dropdownlist.....) { case "BuyOrderDate": ocr.DataDefinition.FormulaFields["GroupName"].Text = "{t_BuyOrder.BuyOrderDate}"; case "State": ocr.DataDefinition.FormulaFields["GroupName"].Text = "{t_BuyOrder.State}"; .................. } CrystalReportViewer1.ReportSource = ocr; CrystalReportViewer1.DataBind();

 

 

你可能感兴趣的:(动态改变水晶报表分组)