Gridview 行变色和行按钮调用前端js

时间:2022-02-09 16:06:11

1.鼠标移动某一行 ,变色

protected void GridView_RowDataBound(object sender, GridViewRowEventArgs e)

    {

    if (e.Row.RowType == DataControlRowType.DataRow)

    {

    //鼠标经过时,行背景色变

    e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor='#00A9FF'");

    //鼠标移出时,行背景色变

    e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='#FFFFFF'");
  //设置悬浮鼠标指针形状为“下手”
    e.Row.Attributes["style"] = "cursor:pointer";
} }

2.编辑按钮调用前端的js 方法

 protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
//获取gridview里的编辑按钮
ImageButton buttonE = new ImageButton();
buttonE = (ImageButton)e.Row.FindControl("IB_Edit"); if (e.Row.RowType == DataControlRowType.DataRow)
{
        
DataRowView drv = (DataRowView)e.Row.DataItem; string SYSID_Floor = drv["SYSID_Meter"].ToString();
          //给按钮添加onclick属性,调用前端的js方法 updateNav()
buttonE.Attributes["onclick"] = "return UpdateNav(" + SYSID_Floor + ")";
buttonE.CommandName = "Edit";
}
}

前端js

<script>

 function UpdateNav(floorId) {

            //iframe层-父子操作
var index = layer.open({
title: "修改接表点信息",
type: 2,
area: ['700px', '530px'],
fix: false, //不固定
maxmin: true,
content: "ad_meter_detail.aspx?SYSID=" + floorId
});
//重新给指定层设定width、top等
layer.style(index, {
top: '15px'
});
return false; }
</script>