private ReportDocument myReport =new ReportDocument();
void Bind_load()
{
string rpt_Path = Server.MapPath("Rpt/Active_Column.rpt");
myReport.Load(rpt_Path);
StringBuilder strSql =new StringBuilder();
strSql.Append("select * from Class");
DataTable dt_head = SqlHelper.ExecuteDataTable(SqlHelper.ConnectionString, CommandType.Text, strSql.ToString(), null);
dt_head.TableName ="Test";
if (dt_head.Rows.Count >0)
{
for (int i =0; i < dt_head.Rows.Count; i++)
{
((TextObject)myReport.ReportDefinition.ReportObjects[i]).Text = dt_head.Rows[i]["_class_name"].ToString();
//myReport.ReportDefinition.ReportObjects[i].Left = 15 * (i+2); //排版
myReport.ReportDefinition.ReportObjects[i].ObjectFormat.EnableCanGrow =true;//字段字适应
strSql.Remove(0, strSql.Length);
strSql.AppendFormat("select * from Student where _class_id='{0}'", dt_head.Rows[i]["_class_id"].ToString());
DataTable dt_detail = SqlHelper.ExecuteDataTable(SqlHelper.ConnectionString, CommandType.Text, strSql.ToString(), null);
if (dt_detail.Rows.Count >0)
{
for (int j =0; j < dt_detail.Rows.Count; j++)
{
myReport.DataDefinition.FormulaFields[i].Text ="'"+ dt_detail.Rows[j]["_student_name"].ToString() +"'";
}
}
}
}
Crys_View1.ReportSource = myReport;
Crys_View1.RefreshReport();
}