. The code to generate a two-dimensional table in net

Source: Internet
Author: User

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

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.