Dynamically change the crystal report Group

Source: Internet
Author: User

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 ();

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.