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