Today, when the data at work is Excel, when using the DataGrid, the table header is required to be two rows. It has never been used before. It makes me difficult and does not want to use the table on the client, I felt that the readability was too bad. After studying it for a while, I finally found a solution. I first came up with a solution. Due to the time relationship, I did not sort it out. Haha.
Private void maid (Object sender, system. Web. UI. webcontrols. datagriditemeventargs E)
{
Listitemtype itemtype = E. Item. itemtype; // obtain the category of the currently created row
Int J = 0;
If (itemtype = listitemtype. header) // when the header is executed
{
Maid trnew = new maid (0, 0, listitemtype. header );
For (INT I = 0; I <datagrid1.columns. Count; I ++ ){
String strvalue = maid [I]. headertext;
If (strvalue. substring (0, 2). Equals ("A volume "))
{
String [] strarr = strvalue. Split (',');
Trnew. cells. Add (New tablecell ());
Trnew. cells [J]. Text = strarr [1];
Trnew. cells [J]. columnspan = 3;
Trnew. cells [J]. width = unit. pixel (180 );
Trnew. cells [J]. Height = unit. pixel (22 );
E. Item. cells [I]. Text = strarr [0];
J = J + 1;
}
Else {
If (maid [I]. headertext! = "B volume" & datagrid1.columns [I]. headertext! = "Comprehensive ")
{
Trnew. cells. Add (New tablecell ());
Trnew. cells [J]. Text = E. Item. cells [I]. text;
Trnew. cells [J]. rowspan = 2;
J = J + 1;
}
}
}
J = 0;
For (INT I = 0; I <datagrid1.columns. Count; I ++)
{
If (maid [I]. headertext! = "B volume" & datagrid1.columns [I]. headertext! = "Comprehensive" & datagrid1.columns [I]. headertext. substring (0, 2 )! = "Volume ")
{
E. Item. cells. removeat (j );
}
Else {
J = J + 1;
}
}
Datagrid1.controls [0]. Controls. addat (0, trnew );
}
}