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:
Copy Code code 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 of
ArrayList almonth = new ArrayList (); Code
Hashtable ht = new Hashtable ();
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);
}
}
the code generated by the Web Forms Designer #region The code generated by the Web Forms Designer
override protected void OnInit (EventArgs e)
{
//
//CodeGen: This call is required for the ASP.net Web forms Designer.
//
InitializeComponent ();
base. OnInit (e);
}
/**////
///Designer supports the desired method-do not modify
with the Code Editor
///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 Name list
public string GetData2 (string statid)
{
STATISTICSB stat=new STATISTICSB ();
return Stat.changetoname (Statid);
}