how to open new window on click link button in gridview

Last Reply on Jun 26, 2012 04:11 AM By Mudassar

Posted on Jun 26, 2012 03:58 AM

Hi friends...

i have gridview with link button.. if i click on link button to open new window with pdf file.




Posted on Jun 26, 2012 04:11 AM

You will need to use HyperLink

    <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false">
            <asp:BoundField DataField="Item" />
                    <asp:HyperLink ID="HyperLink1" runat="server" Target = "_blank" Text = "Show PDF" NavigateUrl = '<%# Eval("url") %>'></asp:HyperLink>


 protected void Page_Load(object sender, EventArgs e)
        if (!Page.IsPostBack)
            DataTable dt = new DataTable();
            dt.Columns.AddRange(new DataColumn[2] { new DataColumn("Item"), new DataColumn("Url") });
            dt.Rows.Add("Shirt", "~/PDF/Shirt.pdf");
            dt.Rows.Add("Football", "~/PDF/Football.pdf");
            dt.Rows.Add("Bat", "~/PDF/Bat.pdf");
            GridView1.DataSource = dt;


I agree, here is the link: