设置datagrid的背影及对单元格进行设置

   //如果是数据项并且是交替项
   if(e.Item.ItemType == ListItemType.Item  || e.Item.ItemType == ListItemType.AlternatingItem)
   {
    //添加自定义属性,当鼠标移过来时设置该行的背景色为"6699ff",并保存原背景色
    e.Item.Attributes.Add("onmouseover","currentcolor=this.style.backgroundColor;this.style.backgroundColor='#6699ff'");
    //添加自定义属性,当鼠标移走时还原该行的背景色
    e.Item.Attributes.Add("onmouseout","this.style.backgroundColor=currentcolor");

   }
   //如果当前项不为空
   if(e.Item.ItemIndex != -1 )
   {
    //取得当前项的索引值加1,因为项的索引值是从0开始的.
    int orderID = e.Item.ItemIndex+1;
    //设置第一列为的单元格内容为当前项索引值加1
    e.Item.Cells[0].Text = orderID.ToString();

    //如果库存为零,则设置该行的背景色为蓝色
    if((e.Item.Cells[8].Text)=="0.00")
     e.Item.Cells[8].CssClass="ItemStyleRightBoldRed";
   }

原文地址:https://www.cnblogs.com/hhq80/p/657399.html