如何在网格视图中的链接按钮单击事件上重定向到不同的页面 [英] How to redirect to a different page on the link button click event in grid view

查看:88
本文介绍了如何在网格视图中的链接按钮单击事件上重定向到不同的页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在网格视图中有一个链接按钮,点击链接按钮我已经分配了一个网址并且它在同一个标​​签中重定向,我们可以重定向到不同的标签或不同的窗口吗?



我的尝试:



I have a link button in grid view and on click of the link button i have assigned a url and it is redirecting in the same tab, Can we redirect to a different tab or different window ?

What I have tried:

<asp:LinkButton ID="LinkButton1" runat="server"  OnCommand="LinkButton_Click"  Text="Link" CommandArgument='<%# Eval("T_Link") %>'></asp:LinkButton>







protected void LinkButton_Click(Object sender, CommandEventArgs e)
  {
      strURL = "";
      LinkButton lb = (LinkButton)sender;
      GridViewRow row1 = (GridViewRow)lb.NamingContainer;
      strURL = e.CommandArgument.ToString();
      Response.Redirect(strURL);
  }

推荐答案

不幸的是,LinkBut​​ton隐藏了标准'target' [ ^ ]属性...

您可以使用简单的HTML代码或HyperLink [ ^ ]控件。 ..
LinkButton unfortunately hides the standard 'target'[^] attribute...
You may use simple HTML code or the HyperLink[^] control...


尝试



try

protected void LinkButton_Click(Object sender, CommandEventArgs e)
       {
            strURL = "";
           LinkButton lb = (LinkButton)sender;
           GridViewRow row1 = (GridViewRow)lb.NamingContainer;
           strURL = e.CommandArgument.ToString();
           Response.Write("<script>");
           Response.Write("window.open('"+strURL+"','_blank')");
           Response.Write("</script>");
       }





备用有效的解决方案

锚点标签替换 linkbutton



Alternate and effective solution
replace the linkbutton with an anchor tag

<a href='<%# Eval("T_Link") %>' target="_blank">Link</a>


这篇关于如何在网格视图中的链接按钮单击事件上重定向到不同的页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆