Change GridView RowColor OnMouseClick

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


和上一片文章类似,只是触发的事件变成了onclick

主要代码
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 Function:

<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 00:14  stswordman  阅读(165)  评论(0编辑  收藏  举报