It took a long time to find it. NET to generate two-dimensional form of code, do not dare to enjoy, now posted out for everyone to see, I believe it helps everyone.
The 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 (); Kinds
ArrayList almonth = new ArrayList (); Code
Hashtable ht = new Hashtable ();
Webjx.com
foreach (DataRow dr in Dt. Rows)
... {
String sdept = dr["C"]. ToString ();
String sMonth2 = dr["P"]. ToString ();
Convert the Origin code to the origin name
String smonth = GetData2 (sMonth2);
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 number of a species
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);
}
}
Web Forms Designer generated Code #region Web Forms Designer generated code
Override protected void OnInit (EventArgs e)
... {
//
CodeGen: This call is required for the ASP.net Web forms Designer.
//
InitializeComponent ();
Base. OnInit (e);
}
/**////
Designer supports required methods-do not use the Code editor to modify
The contents 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"];
}
Get a list of names
public string GetData2 (string statid)
... {
STATISTICSB stat=new STATISTICSB ();
Return Stat.changetoname (Statid);
}