后台代码:
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes.Add("style", "cursor:pointer;"); // 将光标设为手形
// 当鼠标放上去的时候 先保存当前行的背景颜色 并给附一颜色
e.Row.Attributes.Add("onmouseover", "currentcolor=this.style.backgroundColor;this.style.backgroundColor='pink',this.style.fontWeight='';");
// 当鼠标离开的时候 将背景颜色还原的以前的颜色
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=currentcolor,this.style.fontWeight='';");
e.Row.Attributes.Add("OnClick", "ClickEvent('" + e.Row.Cells[1].Text + "')");
}
}
前台代码:
<script type="text/javascript">
function ClickEvent(d) {
//window.alert("事件类型: OnClick 作用对象: " + d);
window.open("ShowMsg.aspx?Title=" + d); // 打开链接
}
</script>