水晶報表動態分組
时间:2010-11-05 来源:災爺
在公式编辑器中 随便拖一个字段,设为{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}";
...................
}
以下是部分伪码,只求表达意义:
view plaincopy to clipboardprint?
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();
本文来自CSDN博客,转载出处:http://blog.csdn.net/csui2008/archive/2010/06/19/5679918.aspx