DataGrid单击改变颜色
在Item_Create中添加代码:
#region DataGrid Item Create
public void DataGrid_ItemCreate(objectsender,System.Web.UI.WebControls.DataGridItemEventArgs e)
{
if(e.Item.ItemType==ListItemType.Item||e.Item.ItemType==ListItemType.AlternatingItem)
{
e.Item.Attributes.Add("onclick","javascript:return CG(this);");//单击改变颜色
}
}
#endregion
客户端代码:(javascript):
<script language=javascript>
function CG(obj)
{
var Curr_TR=document.all.tags("tr");
for(var i=1;i<Curr_TR.length;i++)
{
Curr_TR[i].Style.backgroundColor="white";
}
if(obj.style.backgroundColor="yellow")
{
obj.style.backgroundColor="white";
}
else
{
obj.style.backgroundColor="yellow";
}
}
</script>