[ASP. NET + C #] DataGrid Tips 1 (how to flexibly control the table header)

Source: Internet
Author: User
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 );
}
}

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.