62,041
社区成员
发帖
与我相关
我的任务
分享
//这个函数是关键,当数据行绑定后发生
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
//下面三句代码可以实现你的效果,如果不合适,自己可以比照着修改一下。
string cellvalue = e.Row.Cells[0].Text;
string js = string.Format("alert(\"{0}\");", cellvalue);
e.Row.Attributes.Add("onclick", js);
//下面两句代码是添加鼠标效果,可以省略,当鼠标移动到行上时,变颜色
e.Row.Attributes.Add("onmouseover", "currentcolor=this.style.backgroundColor;this.style.backgroundColor='#ccddff',this.style.fontWeight='Bold';");
//当鼠标离开的时候 将背景颜色还原的以前的颜色
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=currentcolor,this.style.fontWeight='';");
}
}