简体   繁体   English

如何在RowCommand事件上使用GridView打开新窗口?

[英]How to open a new window by using GridView On RowCommand Event?

I have an asp GridView from where, I am using RowCommand and take some value from this page to another page and I want to open that page on to new window. 我在哪里有一个ASP GridView,我正在使用RowCommand,并从该页面取一些值到另一个页面,所以我想将该页面打开到新窗口。

protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
   if (e.CommandName == "Trans")
   {
       Response.Redirect("APIwiserecharge.aspx?
       DisplayID="objdl.Encode(e.CommandArgument.ToString()));
   }
}

and at the .aspx page im using this. 并在.aspx页面上使用此代码。

            <asp:TemplateField HeaderText="APIDetails" ItemStyle-Width="200px">
              <ItemTemplate>
              <asp:LinkButton ID="trans" runat="server"CommandName="TransText="Details" 
              CommandArgument = '<%#Eval("DisplayID") %>'> 
               </asp:LinkButton>
             </ItemTemplate>
            </asp:TemplateField>

Please try with the below code snippet. 请尝试使用以下代码段。

protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
    if (e.CommandName == "Trans")
    {
        Response.Write("<script>window.open('APIwiserecharge.aspx?DisplayID=' + objdl.Encode(e.CommandArgument.ToString()) ,'_blank');</script>");
        //OR
        ScriptManager.RegisterStartupScript(Page, typeof(Page), "OpenWindow1", "window.open('APIwiserecharge.aspx?DisplayID=" + objdl.Encode(e.CommandArgument.ToString()) + "');",true);
        //OR
        Page.ClientScript.RegisterStartupScript(GetType(), "OpenWindow1", "window.open('APIwiserecharge.aspx?DisplayID=" + objdl.Encode(e.CommandArgument.ToString()) + "');", true);
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM