using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.IO;
using System.Configuration;
using System.Data;

namespace uploadfile
{
    public partial class Home : System.Web.UI.Page
    {

        protected void Page_Load(object sender, EventArgs e)
        {


        }


        protected void Button1_Click1(object sender, EventArgs e)
        {

        }

        protected void Button1_Click(object sender, EventArgs e)
        {


            DataTable thisTable = new DataTable();
            DataTable MainTable = new DataTable();
            string cs = ConfigurationManager.ConnectionStrings["uploadfile"].ConnectionString;
            SqlConnection con = new SqlConnection(cs);
            string s = TextBox1.Text;
            string[] words = s.Split(' ');
            string arr = String.Join(",", words);
            foreach (string word in words)
            {
                Console.WriteLine(word);
                SqlCommand cmd = new SqlCommand("select * from Table2 where Name like  '%" + word + "%'OR Tages like '%" + word + "%'", con);

                con.Open();
                SqlDataReader rdr = cmd.ExecuteReader();
                thisTable.Load(rdr);


                //cmd.ExecuteNonQuery();
                //SqlDataAdapter da = new SqlDataAdapter();
                //da.SelectCommand = cmd;
                //DataSet ds = new DataSet();
                //da.Fill(ds, "Data");
                //     MainTable = thisTable.Copy();
                ViewState["dt"] = thisTable;
                DataTable dt = (DataTable)ViewState["dt"];
                dt = thisTable.Copy();
                dt.Merge(thisTable);

                dt = dt.DefaultView.ToTable(true, "Name", "Type", "Tages", "Facilitator");
                GridView1.DataSourceID = null;
                GridView1.DataSource = dt;
                GridView1.DataBind();
                con.Close();

            }
        }
        protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "Download")
            {
                Response.Clear();
                Response.ContentType = "application/octect-stream";
                Response.AppendHeader("content-disposition", "filename=" + e.CommandArgument);
                Response.TransmitFile(Server.MapPath("~/Data/") + e.CommandArgument);
                Response.End();
            }
        }

        protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {

        }

        protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {

        }





    }

}
