我有如下所述的Gridview:
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="TrackingNumber" OnSelectedIndexChanged="GridView1_SelectedIndexChanged1"
DataSourceID="SqlDataSource1">
<Columns>
<asp:BoundField DataField="TrackingNumber" HeaderText="TID" ReadOnly="True" SortExpression="TrackingNumber" />
<asp:BoundField DataField="NationalCode" HeaderText="AID" SortExpression="NationalCode" />
<asp:BoundField DataField="ApplicantFName" HeaderText="AFName" SortExpression="ApplicantFName" />
<asp:BoundField DataField="ApplicantSex" HeaderText="ASex" SortExpression="ApplicantSex"/>
<asp:BoundField DataField="dateOfRegister" dataformatstring="{0:yyyy/MM/dd}" HeaderText="RegisterDate" SortExpression="dateOfRegister"/>
<asp:CommandField ButtonType="Image" SelectImageUrl="~/Admin/images/select.png" ShowSelectButton="True" />
</Columns>
</asp:GridView>
在代码后面我编写了这段代码:
protected void GridView1_SelectedIndexChanged1(object sender, EventArgs e)
{
Session["TID"] = GridView1.SelectedRow.Cells[0].Text;
Response.Redirect("../Recruitment/InitPrint.aspx");
}
当用户点击命令字段按钮时,页面重定向到InitPrint.aspx
,我的代码运行良好。但我希望InitPrint.aspx
在新的标签页中打开,Session["TID"]
将在那里阅读
谢谢你的考虑。
答案 0 :(得分:2)
请检查以下代码。希望它能帮到你
protected void GridView1_SelectedIndexChanged1(object sender, EventArgs e)
{
Session["TID"] = GridView1.SelectedRow.Cells[0].Text;
ScriptManager.RegisterStartupScript(Page, Page.GetType(), "popup", "window.open('page.aspx','_blank')", true);
}
答案 1 :(得分:1)
没有直接的方法,你必须使用类似的东西:
protected void GridView1_SelectedIndexChanged1(object sender, EventArgs e)
{
Session["TID"] = GridView1.SelectedRow.Cells[0].Text;
ScriptManager.RegisterStartupScript(Page, typeof(Page), "OpenWindow", "window.open("'../Recruitment/InitPrint.aspx','_blank'");",true);
}
答案 2 :(得分:0)
您可以将目标设置为空白。
Response.Write("<script>window.open('../Recruitment/InitPrint.aspx','_blank');</script>");
并访问该页面中的会话值。
以下链接可以为您提供更多帮助 ASP.Net-Response.Redirect-or-Server.Transfer-Open-new-window