Code for generating a two-dimensional table in. Net

Source: Internet
Author: User

I have found the code for generating two-dimensional tables in. NET for a long time. I am afraid to share it with you. Now I will post it for you to see. I believe it will be helpful to you.

The Code is as follows:

Copy codeThe Code is as follows:


Void Page_Load (object o, EventArgs e)
...{
DataTable dt = GetData (); // assume GetData returns the DataTable
// Probably better to use Hashtable for depts and months too, but to keep the order, let's use ArrayList
String sSeparator = ":";
ArrayList alDept = new ArrayList (); // type
ArrayList alMonth = new ArrayList (); // code
Hashtable ht = new Hashtable ();
Foreach (DataRow dr in dt. Rows)
{
String sDept = dr ["c"]. ToString ();
String smonth1 = dr ["p"]. ToString ();
// Convert the origin code to the origin name
String sMonth = GetData2 (smon22 );
If (! AlDept. Contains (sDept ))
AlDept. Add (sDept );
If (! AlMonth. Contains (sMonth ))
AlMonth. Add (sMonth );
Ht [sDept + sSeparator + sMonth] = dr ["a"];
}
TableRow tr = new TableRow ();
TableCell tc = new TableCell ();
// Tc. Text = "";
// Tr. Cells. Add (tc );
Foreach (string sDept in alDept)
{
Int I = 0; // used to calculate the quantity of a certain type
Foreach (string sMonth in alMonth)
{
If (ht [sDept + sSeparator + sMonth] = null)
{
I = I + 0;
}
Else
{
I = I + int. Parse (ht [sDept + sSeparator + sMonth]. ToString ());
}
}
Tc = new TableCell ();
Tc. Text = sDept + "(" + I + ")";
Tr. Cells. Add (tc );
}
/** // * Foreach (string sDept in alDept)
{
Tc = new TableCell ();
Tc. Text = sDept;
Tr. Cells. Add (tc );
}*/
Table1.Rows. Add (tr );
Foreach (string sMonth in alMonth)
{
Tr = new TableRow ();
/** // * Tc = new TableCell ();
Tc. Text = sMonth;
Tr. Cells. Add (tc );*/
Foreach (string sDept in alDept)
{
Tc = new TableCell ();
If (ht [sDept + sSeparator + sMonth] = null)
{
Tc. Text = sMonth + "(0 )";
}
Else
{
Tc. Text = sMonth + "(" + ht [sDept + sSeparator + sMonth]. ToString () + ")";
}
Tr. Cells. Add (tc );
}
Table1.Rows. Add (tr );
}
}
Code generated by Web form designer # code generated by region Web Form Designer
Override protected void OnInit (EventArgs e)
{
//
// CODEGEN: This call is required by the ASP. NET Web form designer.
//
InitializeComponent ();
Base. OnInit (e );
}
/**////
/// The designer supports the required methods-do not use the code editor to modify
/// Content of this method.
///
Private void InitializeComponent ()
{
This. Load + = new System. EventHandler (this. Page_Load );
}
# Endregion
Public DataTable GetData ()
{
StatisticsB stat = new StatisticsB ();
DataSet dataset = stat. byStone ();
Return dataset. Tables ["stat"];
}
// Obtain the name list
Public string GetData2 (string statid)
{
StatisticsB stat = new StatisticsB ();
Return stat. changeToName (statid );
}

Related Article

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.