DataGrid 中間隔色的實現

public void SetDataGridColor(System.Web.UI.WebControls.DataGrid dg,int Col)
  {
   //設置顯示已刪除記錄最後一列
   //DataGrid dg =  this.dginfoHeader;

   int cc=dg.Items.Count;
   //bool flg =true;
   //DataGrid中第一行的底色
   System.Drawing.Color changeColor =new System.Drawing.Color();
   
   System.Drawing.Color FirstColor =new System.Drawing.Color();
   FirstColor =System.Drawing.Color.LightBlue;
   System.Drawing.Color SecondColor =new System.Drawing.Color();
   SecondColor =System.Drawing.Color.White;
   int i=1;
   if (cc >0)
    dg.Items[i-1].BackColor =FirstColor;
    while(i<cc)
   {
    if (dg.Items[i].Cells[Col].Text ==dg.Items[i-1].Cells[Col].Text)
    {
     dg.Items[i].BackColor = dg.Items[i-1].BackColor;
    }
    else
    {
     dg.Items[i].BackColor =changeColor;
    }
    if (dg.Items[i].BackColor==FirstColor)
     changeColor=SecondColor;
    else
     changeColor=FirstColor;
   i =i+1;
   }
  }

你可能感兴趣的:(datagrid)