ASP.net 点击表格弹出窗口


为表格中的对应行/单元格添加属性("onclick"事件及弹窗函数)

    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            //循环每列 判断需要添加打开新窗体脚本的列 如果改行任意位置都能打开新窗体 则 直接执行if内代码  将cell改为e.Row
            foreach (TableCell cell in e.Row.Cells)
            {
                if (e.Row.Cells.GetCellIndex(cell) != 0 && e.Row.Cells.GetCellIndex(cell) != 10 && e.Row.Cells.GetCellIndex(cell) != 11)
                {
                    //模版列 要获取到空间的值 如果是BoundFiled 直接去Text值即可
                    //Label lblId = (Label)e.Row.Cells[0].FindControl("LabVisible");            
                    Session["lblId"] = e.Row.Cells[0].Text;
                    //Response.Write(Session["lblId"]);
                    //弹出新窗体 
                    e.Row.Attributes.Add("onclick", "window.open('../StaffResume/people_windows_open.aspx?','','width=800,height=529,scrollbars=0')");
            //e.Row.Attributes.Add("onclick", "window.showModalDialog('../new_test/newtest_update.aspx?','','dialogWidth=1300px;dialogHeight=500px')"); } }
//鼠标以上的样式 e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#c8c7c6'"); e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c;"); //鼠标样式 e.Row.Style.Add("cursor", "hand"); } }
window.open弹窗可兼容谷歌浏览器和IE浏览器,
window.showModalDialog只兼容IE浏览器
参考资料:
https://www.runoob.com/jsref/met-win-open.html
https://blog.csdn.net/bobwu/article/details/7474703
https://blog.csdn.net/wyply115/article/details/51645822