Keep looking at a simple asp.net application.
The GridView believes that we use a lot of it, and the control is used to display and manipulate multiple lines of data generally. It is also an important part of the header, which is responsible for categorizing the data. And how to show the composite header. This is also very simple.
Displays a composite table header, which can generally be implemented in the background by code. For a table header is made up of multiple header controls, a general default header displays a column. For a composite header, you set the header so that it occupies more than one column or more rows. Or you can add a lot of headers, and each header takes up more than one column or multiple rows.
To look at a composite table header.
If only one header is displayed: Ordinal name age gender industry professional experience,
Now add personal basic information and work information, in fact, the new header is the two header control, they occupy 3 columns, so that the composite table header effect. Look at the code:
Foreground code:
Although the table headers that are set in the foreground are not displayed at the time of display, they still have to be written, because you don't remember them, and then there are columns that need to bind the data.
A onrowcreated event needs to be added to the GridView.
Background code:
protected void Page_Load (object sender, EventArgs e) {if (!
IsPostBack) {DataTable dt = InitData ();
This.dgPersons.DataSource = DT;
This.dgPersons.DataBind ();
}} Private DataTable InitData () {datatable personcollect = new DataTable ();
Personcollect = new DataTable ();
PERSONCOLLECT.COLUMNS.ADD ("p_id");
PERSONCOLLECT.COLUMNS.ADD ("P_name");
PERSONCOLLECT.COLUMNS.ADD ("P_age");
PERSONCOLLECT.COLUMNS.ADD ("P_sex");
PERSONCOLLECT.COLUMNS.ADD ("P_industry");
PERSONCOLLECT.COLUMNS.ADD ("P_job");
PERSONCOLLECT.COLUMNS.ADD ("P_experience");
if (PersonCollect.Rows.Count < 1) {for (int i = 0; i < i++) {
DataRow nrow = Personcollect.newrow (); Nrow["p_id"] = System.Guid.NewGuid ().
ToString ();
nrow["p_name"] = "Northwest poplar";
nrow["P_age"] = 27;
nrow["p_sex"] = "male";
nrow["p_industry"] = "SOFTWARE";
nrow["p_job"] = "Senior Engineer";
nrow["p_experience"] = "several years";
PERSONCOLLECT.ROWS.ADD (Nrow);
} return personcollect;
} protected void dgpersons_rowcreated (object sender, GridViewRowEventArgs e) {switch (E.row.rowtype) {Case datacontrolrowtype.header://row is header row Tablecellcollection Personheader = e.row.cells;//the header row's collection of Cells personheader.clear ()//empty//Add a header for example, and there are three columns in the header, so the serial number is 0 1.
2 Personheader.add (New Tableheadercell ()); Personheader[0]. Attributes.Add ("RowSpan", "2"); Cross 2 lines personheader[0]. Attributes.Add ("colspan", "1"); Personheader[0 across 1 columns].
Attributes.Add ("bgcolor", "darkgreen"); Personheader[0].
Text = "ordinal";
Personheader.add (New Tableheadercell ()); PERSONHEADER[1]. Attributes.Add ("colspan", "3"); Personheader[1 across 3 columns].
Attributes.Add ("bgcolor", "darkyellow"); PERSONHEADER[1].
Text = "Personal basic information"; PersonhEader.
ADD (New Tableheadercell ()); PERSONHEADER[2]. Attributes.Add ("colspan", "3"); Personheader[2 across 3 columns].
Attributes.Add ("bgcolor", "darkblue"); PERSONHEADER[2].
Text = "Work Information </th></tr><tr>";
Add a table header Personheader.add (new Tableheadercell ()); PERSONHEADER[3].
Attributes.Add ("bgcolor", "khaki"); PERSONHEADER[3].
Text = "name";
Personheader.add (New Tableheadercell ()); PERSONHEADER[4].
Attributes.Add ("bgcolor", "khaki"); PERSONHEADER[4].
Text = "Age";
Personheader.add (New Tableheadercell ()); PERSONHEADER[5].
Attributes.Add ("bgcolor", "khaki"); PERSONHEADER[5].
Text = "gender";
Personheader.add (New Tableheadercell ()); PERSONHEADER[6].
Attributes.Add ("bgcolor", "khaki"); PerSONHEADER[6].
Text = "Industry";
Personheader.add (New Tableheadercell ()); PERSONHEADER[7].
Attributes.Add ("bgcolor", "khaki"); PERSONHEADER[7].
Text = "occupation";
Personheader.add (New Tableheadercell ()); PERSONHEADER[8].
Attributes.Add ("bgcolor", "khaki"); PERSONHEADER[8].
Text = "experience"; You can also continue adding//remembering that no matter how many rows of headers, the ordinal number of each column is incremented, and you need to wrap-</th></tr><tr> Brea
K }}
The first several methods are to load data, the Main method is: Onrowcreated event dgpersons_rowcreated.
Keep in mind that no matter how many headers it adds, the number is incremented, and if the header has more than one row, you need to add a newline flag after the head at the end of the line. You can then display the effects of multiple-row headers.
Effects of multiple-row composite headers loaded with data:
Is it particularly simple ...
Code Download: http://download.csdn.net/detail/yysyangyangyangshan/7812499