我有一个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()));
}
}
并在.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>
答案 0 :(得分:1)
请尝试使用以下代码段。
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);
}
}