从文件上传控件中选择图像时,在图像控件中预览图像 [英] Preview the Image in Image Control when I Select Image from File Upload Control

查看:62
本文介绍了从文件上传控件中选择图像时,在图像控件中预览图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尊敬的荣誉

我在asp.net页面和Image Control上都有FileUpload控件.

我在哪里显示在服务器上上传的图像.

当我在服务器上上传之前在FileUpload控件中单击浏览"时,我想要该图像显示.

我像下面的代码一样将图像保存到数据库中.

在Image控件中显示图像时,如何将图像存储到数据库中?

这是我的代码,

Dear Honors

I have FileUpload control on my asp.net page and Image Control.

Where I show image which is uploaded on server.

I want that Image show ,when I click on Browse in FileUpload control before I upload on server.

I save the image into database like the following code.

How can I store the image into database while the image displaying in Image control?

Here My Code,

protected void btnSave_Click(object sender, EventArgs e)
   {


       SqlConnection connection = null;
       try
       {
           FileUpload img = (FileUpload)fupImage;
           Byte[] imgByte = null;
           if (img.HasFile && img.PostedFile != null)
           {

               HttpPostedFile File = fupImage.PostedFile;

               imgByte = new Byte[File.ContentLength];

               File.InputStream.Read(imgByte, 0, File.ContentLength);

           }

           SqlCon = objDB.ufDBConnection();


           string sql = "INSERT INTO tblImage(EmpImage) VALUES(@EmpImage)";
           SqlCommand cmd = new SqlCommand(sql, SqlCon);
           cmd.Parameters.AddWithValue("@EmpImage", imgByte);
           int id = Convert.ToInt32(cmd.ExecuteScalar());

       }
       catch
       {
           Label1.Text = "There was an error";
       }
   }

推荐答案

指定用于图像控制的图像url属性,并且该url应该是您发布的文件url.
specify image url property for image control .and that url should be your posted file url.


这篇关于从文件上传控件中选择图像时,在图像控件中预览图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆