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浏览器
在aspx文件中直接绑定控件弹窗
<asp:Button runat="server" Text="导入用户" class="btn btn-secondary" ID="ImportUsers" OnClientClick="openWin('/Account/UsersInfoImport.aspx')" />
设置弹窗位置居中,通过JS代码实现
<script type="text/javascript"> function openWin(url) { var iWidth = 1000; var iHeight = 500; //获得窗口的垂直位置 var iTop = (window.screen.availHeight - 30 - iHeight) / 2; //获得窗口的水平位置 var iLeft = (window.screen.availWidth - 10 - iWidth) / 2; var win = window.open(url, '导入用户', 'height=' + iHeight + ',innerHeight=' + iHeight + ',width=' + iWidth + ',innerWidth=' + iWidth + ',top=' + iTop + ',left=' + iLeft + ',status=no,toolbar=no,menubar=no,location=no,resizable=no,scrollbars=0,titlebar=no'); win.document.getElementById(user).innerHTML = "dsfghj"; return win; } </script>
cs文件中调用JS代码-必须有return
protected void GridView1_DataBound(object sender, EventArgs e) { foreach (GridViewRow row in GridView1.Rows) { row.Attributes.Add("onclick", "return openWin('/Account/UserInfoConfig.aspx')"); } }
参考资料:
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
转载请注明出处:https://www.cnblogs.com/lei-zi/

浙公网安备 33010602011771号