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.

Urgent......

reagards.

shivanand.

Posted on Jun 26, 2012 04:11 AM

You will need to use HyperLink

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

 

 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;
            GridView1.DataBind();
        }
}