1. Create a formula field groupname:
Drag a field in the Public Editor and set it to {t_buyorder.buyorderdate} (of course, the field in your table)
2. When inserting a group in the report, select the created formula groupname.
3. dynamically control the Report Group in the Code: // use dropdownlist to control the report group.
Swich (dropdownlist ......)
{
Case "buyorderdate": // field name
Report. datadefinition. formulafields ["groupname"]. Text = "{t_buyorder.buyorderdate}"; // This is also a combination of fields.
Case "state ":
Report. datadefinition. formulafields ["groupname"]. Text = "{t_buyorder.state }";
...................
}
The following are part of the pseudo code and only express the meaning:
String SQL = "select * From t_buyorder"; <br/> string dbconfig_ SQL = @ "Data Source = FCC-B1EA5171DD0/sql2005; initial catalog = erp_db; user id = sa; Password = 411325; "; <br/> dataset2 DS = new dataset2 (); <br/> sqlconnection sqlcon = new sqlconnection (dbconfig_ SQL); <br/> sqlcommand sqlcmd = new sqlcommand (SQL, sqlcon); <br/> sqldataadapter sqglad = new sqldataadapter (); <br/> sqglad. selectcommand = sqlcmd; <br/> sqglad. fill (DS, "t_buyorder"); <br/> reportdocument OCR = new reportdocument (); <br/> OCR. load (server. mappath ("dynamicgroup. RPT "); <br/> Cr. setdatasource (Ds. tables ["t_buyorder"]); </P> <p> swich (dropdownlist .....) <br/>{< br/> case "buyorderdate": <br/> OCR. datadefinition. formulafields ["groupname"]. TEXT = "{t_buyorder.buyorderdate}"; <br/> case "state": <br/> OCR. datadefinition. formulafields ["groupname"]. TEXT = "{t_buyorder.state}"; <br/> .................. <br/>}< br/> crystalreportviewer1.reportsource = OCR; <br/> crystalreportviewer1.databind ();