操作DataGrid的ItemDataBound事件private void ID_Grid1_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
ListItemType itemType = e.Item.ItemType;
if (itemType == ListItemType.Item || itemType == ListItemType.AlternatingItem )
{
e.Item.Attributes.Add("onmouseover","this.bgColor=#0000ff");
                   e.Item.Attributes.Add("onmouseout","this.bgColor=#ffffff");
e.Item.Style.Add("CURSOR","hand");
}
}

解决方案 »

  1.   

    我说的是table 
    不是datagrid啊
      

  2.   

    Table tb=new Table();
    TableRow tr;
    TableCell tc;
    for(int i=0;i<5;i++)
    {
    tr=new TableRow();
    for(int j=0;j<5;j++)
    {
    tc=new TableCell();
    tc.Attributes.Add("onmouseover","this.bgColor='#ff0000'");
    tc.Attributes.Add("onmouseout","this.bgColor='#ffffff'");
    tc.Text="...";
    tr.Cells.Add(tc);
    }
    tb.Rows.Add(tr);
    }
    this.Controls[1].Controls.Add(tb);
      

  3.   

    <tr height="20%" onmouseover="ChangeRowColor(this);" onmouseout="ChangeNewRowColor(this)">
    <td>
    Test
    </td>
    </tr><script language="javascript">
    function ChangeRowColor(rowObj)
    {
    rowObj.style.backgroundColor='#FEE6A7';
    }

    function ChangenewRowColor(rowObj)
    {
        rowObj.style.backgroundColor='#FFFFFF';
    }
    </script>
      

  4.   

    同一magiccoder(或许..未必..不过..) ,
    补充一点最好把样式写在一个样式表文件中,这样可以方便的修改样式,vs的样式生成功能很强的。
      

  5.   

    同意magiccoder(或许..未必..不过..),鼠标移过变色就是用事件 onmouseover和onmouseout。
    不过变色会不会丑了点,最好是换图片。
      

  6.   

    不对啊
    我是想把该cell所在的整行和整列的颜色都改变啊
    不是只改变当前的cell啊