本文介绍了在gridview中显示图像。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hii我已经使用下面的代码上传图像了它的工作。图像路径在数据库中存在并且图像也存储在文件夹中bt图像没有在gridview中显示。我该怎么办...使用此代码plzz编辑或修改代码在gridview中显示图像..



Hii i have been uploaded image using below code its working.Image path is gooing in database and image also storing in folder bt image is not displaying in gridview.How can i do.. using this code plzz edit or modify code for show image in gridview..

SqlConnection con = new SqlConnection("Data Source=DEEPAK-PC\\SQLEXPRESS;Initial Catalog=Imageup;User ID=sa;Password=sasa");
   protected void Page_Load(object sender, EventArgs e)
   {

   }

  protected void Button1_Click(object sender, EventArgs e)
   {
       if (FileUpload1.HasFile)
       {
           String str = FileUpload1.FileName;
           //FileUpload1.PostedFile.SaveAs(Server.MapPath(",") + "~//uploadedimages//" + str);


           string FileName= Path.GetFileName(FileUpload1.FileName);
           FileUpload1.SaveAs(Server.MapPath("~/uploadedimages/")+ FileName);
           string path = "~//Uploads//"+str.ToString();
           con.Open();
           SqlCommand cmd = new SqlCommand("insert into FileUploads1 values('" + TextBox1.Text + "','" + path + "')", con);
           cmd.ExecuteNonQuery();
           con.Close();
           Label1.Text = "Image upload Successfully";
       }
       else
       {
           Label1.Text = "Plz select ur image and upload";
       }
       SqlDataAdapter da = new SqlDataAdapter("select * from FileUploads1", con);
       DataTable dt = new DataTable();
       da.Fill(dt);
       GridView1.DataSource = dt;
       DataBind();



   }

推荐答案



FileUpload1.SaveAs(Server.MapPath("~/uploadedimages/")+ FileName);








and the

"insert into FileUploads1 values('" + TextBox1.Text + "','" + path + "'

应该是一样的。

希望这有帮助......

should be same .
Hope this helps...


这篇关于在gridview中显示图像。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 16:59