操作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");
}
}
{
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");
}
}
不是datagrid啊
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);
<td>
Test
</td>
</tr><script language="javascript">
function ChangeRowColor(rowObj)
{
rowObj.style.backgroundColor='#FEE6A7';
}
function ChangenewRowColor(rowObj)
{
rowObj.style.backgroundColor='#FFFFFF';
}
</script>
补充一点最好把样式写在一个样式表文件中,这样可以方便的修改样式,vs的样式生成功能很强的。
不过变色会不会丑了点,最好是换图片。
我是想把该cell所在的整行和整列的颜色都改变啊
不是只改变当前的cell啊