0

asp.net ページに gridview があります。

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="true" CssClass="Gridview"
                    OnRowCommand="GridView1_RowCommand">
                    <Columns>
                        <asp:ButtonField Text="VIEW" ButtonType="link" CommandName="view" />
                    </Columns>
                </asp:GridView>

新しいウィンドウで新しいページを開きたい。

そのために、以下のコードを使用しました(このコードは機能していません!-エラーがないか確認してください)

protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
    if (e.CommandName.Equals("view"))
    {
        int index = Convert.ToInt32(e.CommandArgument);
        GridViewRow gvrow = GridView1.Rows[index];
        String id= gvrow.Cells[1].Text;
        string url = "~/Mypage.aspx?myid=" + id;
        Response.Write("<script>window.open( 'www.google.com' , '-blank' );</script>");
    }
}

GRIDVIEW で実行時にデータをバインドしていますが、 これを念頭に置いてください。

ハイパーリンクフィールドを使用できないように。

gridview でのコーディングを使用して、新しいウィンドウで新しいページを開く方法を提案してください。

4

2 に答える 2

1

からコードを置き換えます

Response.Write("<script>window.open( 'www.google.com' , '-blank' );</script>");

ClientScript.RegisterClientScriptBlock(this.GetType(), "Message", "window.open('www.google.com','_blank');", true);
于 2012-12-07T12:20:45.393 に答える