您的位置:首页 > 其它

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

2012-11-28 10:13 281 查看
在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");
}
记录一下 方便以后查阅。


  
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐