how to open new window and filtering gridview
<p>I have some problem with my coding to open my pdf file at new tab or new window. Then, I'm also have problem  in filtering my gridview. This is because when the gridview was filtered the download button can not work and the pdf can't be download. Here is my aspx coding</p>

<pre><code>&lt;%@ Page Language="C#" AutoEventWireup="true" CodeBehind="ViewDocument.aspx.cs" Title="Untitled Page" %&gt;

  &lt;asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server"&gt;
   &lt;/asp:Content&gt;
  &lt;asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server"&gt;
&lt;center&gt;
    &lt;br /&gt;
    &lt;br /&gt;
    &lt;asp:Label ID="Label1" runat="server" CssClass="title" Text="DOCUMENT LIST"&gt;&lt;/asp:Label&gt;
    &lt;br /&gt;
    &lt;br /&gt;
    &lt;br /&gt;
    &lt;table&gt;
        &lt;tr&gt;
            &lt;td style="text-align: center; padding-left: 25px; padding-right: 25px"&gt;
            &lt;/td&gt;
            &lt;td style="text-align: center"&gt;
                &lt;asp:Button ID="Button1" runat="server" CssClass="button" Text="Contract(Test)" OnClick="Button1_Click" /&gt;
            &lt;/td&gt;
            &lt;td style="text-align: center; padding-left: 25px; padding-right: 25px"&gt;
            &lt;/td&gt;
        &lt;/tr&gt;
    &lt;/table&gt;
    &lt;br /&gt;
    &lt;br /&gt;
&lt;/center&gt;
&lt;asp:MultiView ID="MultiView1" runat="server"&gt;
    &lt;asp:View ID="DocView" runat="server"&gt;
        &lt;center&gt;
            &lt;br /&gt;
            &lt;br /&gt;
            &lt;table&gt;
                &lt;tr&gt;
                    &lt;td style="text-align: center; padding-left: 10px; padding-right: 15px"&gt;
                        &lt;asp:Label ID="Label2" runat="server" Text="Search By :"&gt;&lt;/asp:Label&gt;
                    &lt;/td&gt;
                   &lt;%-- &lt;td style="text-align: center; padding-left: 5px; padding-right: 5px"&gt;
                        &lt;asp:DropDownList ID="DropDownList1" runat="server" CssClass="dropDownMenu"&gt;
                            &lt;asp:ListItem Value="Document Name"&gt;&lt;/asp:ListItem&gt;
                            &lt;asp:ListItem Value="Date"&gt;&lt;/asp:ListItem&gt;
                        &lt;/asp:DropDownList&gt;
                    &lt;/td&gt;--%&gt;
                    &lt;td style="padding-left: 5px; padding-right: 5px"&gt;
                        &lt;asp:TextBox ID="DocSearch" runat="server" CssClass="text-input" Width="200px" MaxLength="100"
                            Font-Names="verdana"&gt;&lt;/asp:TextBox&gt;
                    &lt;/td&gt;
                    &lt;td&gt;
                        &lt;asp:Button ID="Button2" runat="server" CssClass="button" Text="Search" OnCommand="Button2_Command" /&gt;
                    &lt;/td&gt;
                &lt;/tr&gt;
            &lt;/table&gt;
            &lt;br /&gt;
            &lt;br /&gt;
            &lt;br /&gt;
            &lt;asp:GridView ID="GridView1" runat="server" BackColor="White" BorderStyle="Solid"
                BorderColor="#ccc" BorderWidth="2px" GridLines="Horizontal" Width="650px" AutoGenerateColumns="false"
                CellPadding="3" OnRowCommand="ActionCommand" AllowSorting="true"&gt;
                &lt;RowStyle BackColor="#E7E7FF" ForeColor="#4A3C8C" /&gt;
                &lt;Columns&gt;
                &lt;asp:BoundField DataField="folderName"&gt;
                        &lt;ItemStyle CssClass="leftAligment" /&gt;
                    &lt;/asp:BoundField&gt;
                    &lt;asp:BoundField DataField="fileName" HeaderText="DOCUMENT NAME"&gt;
                        &lt;ItemStyle CssClass="leftAligment" /&gt;
                    &lt;/asp:BoundField&gt;
                    &lt;asp:BoundField DataField="Date" HeaderText="DATE / TIME"&gt;
                        &lt;ItemStyle CssClass="centerAlign" /&gt;
                    &lt;/asp:BoundField&gt;
                    &lt;asp:ButtonField CommandName="Open" Text="Open" ButtonType="Link" /&gt;
                    &lt;asp:ButtonField CommandName="Download" Text="Download" /&gt;
                &lt;/Columns&gt;
                &lt;FooterStyle BackColor="#B5C7DE" ForeColor="#4A3C8C" /&gt;
                &lt;PagerStyle BackColor="#E7E7FF" ForeColor="#4A3C8C" HorizontalAlign="Right" /&gt;
                &lt;SelectedRowStyle BackColor="#738A9C" Font-Bold="True" ForeColor="#F7F7F7" /&gt;
                &lt;HeaderStyle BackColor="#4A3C8C" Font-Bold="True" ForeColor="#F7F7F7" /&gt;
                &lt;AlternatingRowStyle BackColor="#F7F7F7" /&gt;
            &lt;/asp:GridView&gt;
        &lt;/center&gt;
        &lt;br /&gt;
        &lt;br /&gt;
        &lt;br /&gt;
    &lt;/asp:View&gt;
&lt;/asp:MultiView&gt;
</code></pre>

<p></p>

<p>my aspx.cs coding</p>

<pre><code>using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;
using System.IO;
using System.Threading;
using System.Net;
using System.Xml;

namespace Hibah_Total_v1._2.Secure
{
public partial class ViewDocument : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            MultiView1.Visible = false;
        }
    }


    protected void Button1_Click(object sender, EventArgs e)
    {
        MultiView1.Visible = true;
        MultiView1.SetActiveView(DocView);
        string folderName = ConfigurationManager.AppSettings["folderPDF"].ToString();
        string path = Server.MapPath("~") + "/Secure/";
        string fullPath = path + folderName;
        string[] filePaths = Directory.GetFiles(fullPath, "*.pdf");
        DataTable table = GetTable(filePaths);

        GridView1.Columns[0].Visible = true;
        GridView1.DataSource = table;
        GridView1.DataBind();
        GridView1.Columns[0].Visible = false;

    }


    public DataTable GetTable(string[] filePaths)
    {
        DataTable table = new DataTable();
        table.Columns.Add("folderName", typeof(string));
        table.Columns.Add("fileName", typeof(string));
        table.Columns.Add("Date", typeof(string));

        DataRow row;
        {
            for (int i = 0; i &lt; filePaths.Length; i++)
            {
                row = table.NewRow();


                row["folderName"] = filePaths[i];
                FileInfo Myfile = new FileInfo(filePaths[i]);
                row["fileName"] = Myfile.Name.ToString();
                row["Date"] = Myfile.CreationTime.ToString();

                table.Rows.Add(row);

            }
        }


        Session["Table"] = table;

        this.GridView1.DataSource = ((DataTable)Session["Table"]).DefaultView;
        this.GridView1.DataBind();

        return table;

    }





    public void ActionCommand(object sender, GridViewCommandEventArgs e)
    {
        string commandName = e.CommandName.ToString().Trim();
        GridViewRow row = GridView1.Rows[Convert.ToInt32(e.CommandArgument)];
        string folderName = ConfigurationManager.AppSettings["folderPDF"].ToString();
        string path = Server.MapPath("~") + "/Secure/";
        string fullPath = path + folderName;
        string[] filePaths = Directory.GetFiles(fullPath, "*.pdf");            
            switch (commandName)
            {
                case "Open":

                    ScriptManager.RegisterStartupScript(Page, typeof(Page), "OpenWindow", "window.open('OpenForm.aspx?path=" + row.Cells[0].Text + "');", true);
                    break;
                case "Download":

                    FileStream fs = new FileStream(row.Cells[0].Text, FileMode.Open, FileAccess.Read);
                    byte[] ar = new byte[(int)fs.Length];
                    fs.Read(ar, 0, (int)fs.Length);
                    fs.Close();

                    Response.AddHeader("content-disposition", "attachment;fileName=" + HttpUtility.UrlEncode(row.Cells[1].Text, System.Text.Encoding.UTF8));
                    Response.ContentType = "application/octectstream";
                    Response.BinaryWrite(ar);
                    Response.End();
                    break;
                default: break;
            }

    }


    protected void Button2_Command(object sender, EventArgs e)
    {
        string folderName = ConfigurationManager.AppSettings["folderPDF"].ToString();
        string path = Server.MapPath("~") + "/Secure/";
        string fullPath = path + folderName;
        string[] filePaths = Directory.GetFiles(fullPath, "*.pdf");

        if (DocSearch.Text.ToString().Trim() != "")
        {
            DataTable dt = (DataTable)Session["Table"];
            var query = from t in dt.AsEnumerable() where t.Field&lt;string&gt;("folderName").StartsWith(DocSearch.Text.ToString().Trim()) || t.Field&lt;string&gt;("folderName").Contains(DocSearch.Text.ToString().Trim()) select t;

            DataTable dtable = new DataTable();
            dtable = query.CopyToDataTable();
            this.GridView1.DataSource = dtable;
            this.GridView1.DataBind();

        }
        else
        {
            this.GridView1.DataSource = ((DataTable)Session["table"]).DefaultView;
            this.GridView1.DataBind();
        }

    }



  }
}
</code></pre>

<p>can anyone help me figure it out???</p>
