protected void dgSjygl_ItemDataBound(object sender, DataGridItemEventArgs e)
    {
        if ((e.Item.ItemType == ListItemType.Item) || (e.Item.ItemType==ListItemType.AlternatingItem))
        {
            //当鼠标移到的时候设置该行颜色
            e.Item.Attributes.Add("onmouseover", "currentcolor=this.style.backgroundColor;this.style.backgroundColor='#6699CC'");
            //当鼠标移走时还原该行的背景色
            e.Item.Attributes.Add("onmouseout", "this.style.backgroundColor=currentcolor");
        }
    }

 

在DataGrid 里面的ItemDataBound事件

//颜色交替显示
鼠标移动 改变Datagrid行的背景颜色
        if (e.Item.ItemIndex >= 0 && e.Item.DataItem is DataRowView)
        
{
            DataRowView row 
= (DataRowView)e.Item.DataItem;
            
int numj = e.Item.Cells.Count;
            
for (int j = 0; j < numj; j++)
          
{
                e.Item.Cells[j].ForeColor 
= System.Drawing.Color.Pink;
                e.Item.Cells[j].BackColor 
= System.Drawing.Color.Blue;
            }

        }

相关文章:

  • 2022-12-23
  • 2021-12-11
  • 2021-09-11
  • 2022-12-23
  • 2021-07-25
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-09-18
  • 2021-07-17
  • 2021-09-18
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案