Change GridView RowColor OnMouseClick

原文地址http://gridviewguy.com/ArticleDetails.aspx?articleID=174

AzamSharp上一篇文章类似,只是触发的事件是onclick而不再是onmouseover

主要代码如下:

服务器端代码:
 protected void MyGridView_RowCreated(object sender, GridViewRowEventArgs e)

{

string rowID = String.Empty;

if (e.Row.RowType == DataControlRowType.DataRow)

{

rowID = "row"+e.Row.RowIndex;

e.Row.Attributes.Add("id","row"+e.Row.RowIndex);

e.Row.Attributes.Add("onclick","ChangeRowColor(" +"'" + rowID + "'" + ")");

}

}

javascript教本:
<script language ="javascript" type="text/javascript">

document.body.style.cursor = 'pointer';

var oldColor = '';

 

function ChangeRowColor(rowID)

{

var color = document.getElementById(rowID).style.backgroundColor;

if(color != 'yellow')

oldColor = color;

if(color == 'yellow')

document.getElementById(rowID).style.backgroundColor = oldColor;

else document.getElementById(rowID).style.backgroundColor = 'yellow';

}

</script>

posted on 2006-08-04 08:32  stswordman  阅读(585)  评论(0编辑  收藏  举报