博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

GridView如何实现点击某行的指定列弹出新窗体

Posted on 2012-11-28 10:13  JmrBrvae  阅读(438)  评论(0编辑  收藏  举报
在Gridview的rowdatabind事件中添加如下代码:
protected void GVData_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowIndex > -1) { //循环每列 判断需要添加打开新窗体脚本的列 如果改行任意位置都能打开新窗体 则 直接执行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"); //弹出新窗体 cell.Attributes.Add("onclick", "window.showModalDialog('../GiveScore/DetailMoonDetailResult.aspx?Id=" + lblId.Text + "','','dialogWidth=700px;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"); }
记录一下 方便以后查阅。