GvidView中添加HyperLink控件打開新頁,但HyperLink不支援JS,可以通過以下的方法讓其支持.

GvidView中添加HyperLink控件打開新頁,但HyperLink不支援JS,可以通過以下的方法讓其支持.

1.在頁面中添加如下JS語句:

  1. <script type="text/javascript">
  2.     function ShowWindow(URLStr, popWinName, left, top, width, height) {
  3.         window.open(URLStr, popWinName, 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,copyhistory=yes,width=' + width + ',height=' + height + ',left=' + left + ', top=' + top + ',screenX=' + left + ',screenY=' + top + '');
  4.     }
  5.     function showMyModalDialog(url, width, height){
  6.       showModalDialog(url, '','dialogWidth:' + width + 'px;dialogHeight:' + height + 'px;center:yes;status:no;scroll:no;help:no');
  7.     }
  8.     function showMyModelessDialog(url, width, height){
  9.       showModelessDialog(url, '','dialogWidth:' + width + 'px;dialogHeight:' + height + 'px;center:yes;status:no;scroll:no;help:no');
  10.     }
  11. </script>

2.添加GridView1_RowDataBound事件:

  1. protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
  2.     {
  3.         if (e.Row.RowType == DataControlRowType.DataRow)
  4.         {
  5.             e.Row.Cells[3].Attributes["onclick"] = "javascript:ShowWindow('hyperlink.aspx?name=" + e.Row.Cells[2].Text.ToString() + "','hyperlink',100,100,400,300);";
  6.             string JS = "hyperlink.aspx?id=" + e.Row.Cells[0].Text.ToString() + "&type=" + e.Row.Cells[1].Text.ToString();       
  7.             e.Row.Cells[4].Text = "<a href=/"javascript:/" οnclick=/"javascript:ShowWindow('" + JS + "','添加',100,100,400,300);/">添加信息</a>";
  8.             e.Row.Cells[5].Text = "<a href=/"javascript:/" οnclick=/"javascript:ShowWindow('hyperlink.aspx?id=" + e.Row.Cells[2].Text.ToString() + "','查看',100,100,400,300);/">查看明细</a>";
  9.         }
  10.     }

此方法為GridView中的HyperLink打開新窗體的好處:不會去刷新當前頁,直接打開新頁.

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值