protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
string key = this.GridView1.DataKeys[e.Row.RowIndex].Value.ToString();
e.Row.Attributes.Add("onmouseover", "if(this!=prevselitem){this.style.backgroundColor='#Efefef'};this.style.cursor='hand';");//当鼠标停留时更改背景色
e.Row.Attributes.Add("onmouseout", "if(this!=prevselitem){this.style.backgroundColor='#ffffff'}");//当鼠标移开时还原背景色
e.Row.Attributes.Add("onclick", e.Row.ClientID.ToString() + ".checked=true;selectx(this);setvalue('" + key + " ')");
// e.Row.Attributes.Add("onclick", "alert('" + key + " ')");
}
}
<script type="text/javascript">
var prevselitem=null;
function selectx(row)
{
if(prevselitem!=null)
{
prevselitem.style.backgroundColor='#ffffff';
}
row.style.backgroundColor='PeachPuff';
prevselitem=row;
}
function setvalue(obj)
{
document.getElementById("Hidden1").value=obj;
document.getElementById("dd").innerHTML=obj;
alert(obj);
document.all('Button1').click();
}
</script>