Are you willing to discuss the technology of data summary reports: Data summary and the generation of multiple headers in the GridView?

Source: Internet
Author: User
For more information, see:

Summary row in the DataGrid Control: http://www.microsoft.com/china/MSDN/library/data/dataAccess/Summary+Rows+in+DataGrid+Controls.rtf.mspx? Mfr = true

Example of resumttable file:
/Files/lovenets2008/FIG
Functions used:

Public static DataTable MakePivotFromTable_Demo (DataTable source, string columeTop, string columeLeft, string columeSum)
{
DataTable dest = new DataTable ("Pivoted" + source. TableName );

// The remaining dest columns are from each source table row (1st column)
// For (int I = 1; I <source. Columns. Count-1; I ++)
//{
// Dest. Columns. Add (source. Columns [I]. ColumnName );
//}
// Source. LoadDataRow (ll, bbbb );

DataTable dtCols = new DataTable ();
DtCols. Columns. Add (columeTop );
DtCols. Constraints. Add ("key", dtCols. Columns [0], true );

Foreach (DataRow r in source. Rows)
{
DtCols. loadDataRow (r [columeTop]. toString (). split (",". toCharArray (), true); // assign each row the Product name (r [0])
}

Dest. Columns. Add (columeTop); // "summary ");
// Dest. Columns. Add (columesSum );

Foreach (DataRow r in dtCols. Rows)
{
Dest. Columns. Add (r [columeTop]. ToString (); // assign each row the Product name (r [0])
}

// Now add one row to the dest table for each column in the source, limit t
// The first which is the Product, in our case
Dest. Constraints. Add ("key", dest. Columns [0], true );

For (int I = 0; I <source. Rows. Count; I ++)
{
Dest. LoadDataRow (source. Rows [I] [columeLeft]. ToString (). Split (",". ToCharArray (), true );
// DataRow dr = dest. NewRow ();
// Dr [0] = source. Rows [I] [columesLeft];
// Try
//{
// Dest. Rows. Add (dr );
//}
// Catch (Exception ){}
}

// Now move the source columns to their position in the dest row/cell matrix
// Starting down the destination rows, and keep ss the columns
For (int r = 0; r <dest. Rows. Count; r ++)
{
For (int c = 1; c <dest. Columns. Count; c ++)
{
Float amounts = 0;
DataRow [] drs = source. Select (source. Columns [columeTop]. ColumnName + "= '" + dest. Columns [c]. ColumnName
+ "'AND" + source. Columns [columeLeft]. ColumnName + "='" + dest. Rows [r] [0]. ToString () + "'");
Foreach (DataRow dr in drs)
{
Amounts + = float. Parse (dr [columeSum]. ToString ());
}
If (drs. Length> 0) dest. Rows [r] [c] = amounts;
}
}
// Dest. Select ();
// DataTable dt = dest. Constraints. Add (;
// Dest. Select ("Select *");
Dest. AcceptChanges ();
Return dest;
}

The progress will be posted here one after another.

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.