Click here to Skip to main content
15,893,790 members
Please Sign up or sign in to vote.
3.33/5 (3 votes)
See more:
The code below are working good but the problem I have is that after uploading a file its not appearing in gridview.

C#
protected void GridView1_SelectedIndexChanged1(object sender, EventArgs e)
        {
           SqlConnection con = new SqlConnection("Data Source=.;Initial Catalog=MinisanteDb;Integrated Security=True");
            SqlCommand com = new SqlCommand("select name,type,data from  uploadd where name=@name", con);
            com.Parameters.AddWithValue("name", GridView1.SelectedRow.Cells[1].Text);
            con.Open();
            //con.Close();

            SqlDataReader dr = com.ExecuteReader();


            if (dr.Read())
            {
                Response.Clear();
                Response.Buffer = true;
                Response.ContentType = dr["type"].ToString();
                Response.AddHeader("content-disposition", "attachment;filename=" + dr["name"].ToString());     // to open file prompt Box open or Save file         
                Response.Charset = "";
                Response.Cache.SetCacheability(HttpCacheability.NoCache);
                Response.BinaryWrite((byte[])dr["data"]);
                Response.End();
            }
        }
Posted
Updated 5-Mar-13 12:22pm
v3

in pageload plz write gridview bind code under ispostback==false ...
 
Share this answer
 
Comments
Gilbertinino 7-Mar-13 3:40am    
When binding code of gridview in page load with ispostback==false I got this error Object reference not set to an instance of an object.
i'm not clear what you want in your gridview. if it's the filename you want to show in a cell of your gridview try using a datasource to your gridview and/or also can try to use a custom template column in your gridview.and also check for postback, without postback u'll always find a empty grid.
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900