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