venky n

venky n

  • NA
  • 110
  • 38.6k

image view in gridviewcontrol for row wise(horizontal)

Mar 7 2015 2:13 AM
How to  morethan one  image single field in gridviewcontrol for row wise(horizontal)



protected void btnUpload_Click(object sender, EventArgs e)
  {
  if (FileUpload1.PostedFile != null)
  {
  string FileName = Path.GetFileName(FileUpload1.PostedFile.FileName); 

  //Save files to disk
  FileUpload1.SaveAs(Server.MapPath("images/" +  FileName));

  //Add Entry to DataBase
  String strConnString = System.Configuration.ConfigurationManager.ConnectionStrings["conString"].ConnectionString;
  SqlConnection con = new SqlConnection(strConnString);
  string strQuery = "insert into tblFiles (FileName, FilePath) values(@FileName, @FilePath)";
  SqlCommand cmd = new SqlCommand(strQuery);
  cmd.Parameters.AddWithValue("@FileName", FileName);
  cmd.Parameters.AddWithValue("@FilePath", "images/" + FileName); 
  cmd.CommandType = CommandType.Text;
  cmd.Connection = con;
  try
  {
  con.Open();
  cmd.ExecuteNonQuery();
  Response.Write("image successfully saved!");
  }
  catch (Exception ex)
  {
  Response.Write(ex.Message);
  }
  finally
  {
  con.Close();
  con.Dispose();
  }
  }
  }
  protected void Button1_Click(object sender, EventArgs e)
  {
  DataTable dt = new DataTable();
  String strConnString = System.Configuration.ConfigurationManager.ConnectionStrings["conString"].ConnectionString;
  string strQuery = "select  FilePath from tblFiles order by ID";
  SqlCommand cmd = new SqlCommand(strQuery);
  SqlConnection con =  new SqlConnection(strConnString);
  SqlDataAdapter sda = new SqlDataAdapter();
  cmd.CommandType = CommandType.Text;
  cmd.Connection = con;
  try
  {
  con.Open();
  sda.SelectCommand = cmd;
  sda.Fill(dt);
  GridView1.DataSource = dt;
  GridView1.DataBind(); 
  }
  catch (Exception ex)
  {
  Response.Write(ex.Message);
  }
  finally
  {
  con.Close();
  sda.Dispose();
  con.Dispose();
  }
  }