看代码:
protected void GVVendorSearched_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
//鼠标在哪行,哪行便变色; 鼠标离开,该行颜色恢复正常
e.Row.Attributes.Add("onmouseover", "oldBG=this.style.backgroundColor; this.style.backgroundColor='#E6F5FA';");
//oldBG=this.style.backgroundColor 保存当前行原来的颜色
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=oldBG");
//单击事件(onclick)使用了 setTimeout 延迟,根据实际需要修改延迟时间
//当双击时,通过全局变量 dbl_click 来取消单击事件的响应
e.Row.Attributes["onclick"] = String.Format("javascript:setTimeout(\"if(dbl_click){{dbl_click=false;}}else{{alert('你单击了')}};\", 1000*0.3);");
// 双击,设置 dbl_click=true,以取消单击响应
e.Row.Attributes["ondblclick"] = String.Format("javascript:dbl_click=true;alert('双击了');");
// e.Row.Attributes["title"] = "单击选择行,双击打开详细页面";
}
}
记得:定义一个全局的JS变量:
<script>
var dbl_click = false;
</script>