DataGrid implements simple row grouping

Source: Internet
Author: User

Sometimes, when the values of a row repeat, the grouping display is clearer. You can use the following method to group the data on the premise that the SQL statement for data query must be group by the field you want to group.

//Temporary Storage group value
Private   String Tempyear = String . Empty;

// Add a datagrid_itemdatabound event
Private   Void Datagrid1_itemdatabound ( Object Sender, system. Web. UI. webcontrols. datagriditemeventargs E)
{

String Curyear = E. Item. cells [ 0 ]. Text;
If (E. Item. itemtype = Listitemtype. Item | E. Item. itemtype = Listitemtype. alternatingitem)
{
If (Curyear = Tempyear)
{< br> E. item. cells [ 0 ]. text = " " ;
E. item. cells [ 0 ]. style. add ( " border " , " 0 " );
}
Else
{
Tempyear=Curyear;
E. Item. cells [0]. Backcolor=System. Drawing. color. whitesmoke;
}
}
}

ReferenceArticle:
Advanced DataGrid formating with itemdatabound

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.