如何在gridview中绑定图像 [英] How to bind image in gridview

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

问题描述

如何从服务器文件夹中绑定gridview中的图像..不保存图像路径r数据库中的图像名称..我可以像这样保存图像代码ex-image1,image2并获取数据库中的图像代码并添加图像代码+ _0.jpg ex- image1_0.jpg保存在一个变量imagename中,imagename发送到文件夹n匹配文件夹图像中的imagename ..获取文件夹中的图像并显示在gridview中,并将该图像中的链接按钮放入其打开的新页面。请帮助我先生..



我尝试过:



如何从服务器文件夹中绑定gridview中的图像..不保存图像路径r数据库中的图像名称..我可以像这样保存图像代码ex-image1,image2并获取数据库中的图像代码并添加imagecode + _0。 jpg ex-image1_0.jpg保存在一个变量imagename中,imagename发送到文件夹n匹配文件夹图像中的imagename ..获取文件夹中的图像并显示在gridview中,并将链接按钮放在该图像中打开新页面..请帮助我先生..

How to bind the images in gridview from server folder..not save image path r image name in database.. i could saver the image code ex- image1,image2 like that and fetch the image code in database and add imagecode + _0.jpg ex- image1_0.jpg that save in one variable imagename that imagename send to folder n match the imagename in folder image.. fetch the image in folder and display in gridview and put the link button in that image its open new page.. pls help me sir..

What I have tried:

How to bind the images in gridview from server folder..not save image path r image name in database.. i could saver the image code ex- image1,image2 like that and fetch the image code in database and add imagecode + _0.jpg ex- image1_0.jpg that save in one variable imagename that imagename send to folder n match the imagename in folder image.. fetch the image in folder and display in gridview and put the link button in that image its open new page.. pls help me sir..

推荐答案

这是一个如何从文件夹上传和显示图像的快速示例。首先,您需要创建一个应用程序具有读/写访问权限的文件夹。假设您的应用程序根目录中有一个名为ImageStorage的文件夹,用于存储图像。



然后你有这个HTML标记:

Here's a quick example how to upload and display an image from a folder. First you need to create a folder that your application has read/write access permissions to it. Assuming that you have a folder named "ImageStorage" within the root of your application that stores the images.

Then you have this HTML markup:
<asp:fileupload id="FileUpload1" runat="server" xmlns:asp="#unknown" />  
<asp:button id="Button1" runat="server" text="Upload" onclick="Button1_Click" xmlns:asp="#unknown" />  
<br />  
<asp:image id="Image1" runat="server" xmlns:asp="#unknown" />  





这是相关的代码。





Here's the code associated.

protected void Button1_Click(object sender, EventArgs e) {  
             StartUpLoad();  
}  
     
private void StartUpLoad() {  
        //get the file name of the posted image  
        string imgName = FileUpload1.FileName;  
        //sets the image path  
        string imgPath = "ImageStorage/" + imgName;            
       //get the size in bytes that  
  
       int imgSize = FileUpload1.PostedFile.ContentLength;  
      
       //validates the posted file before saving  
        if (FileUpload1.PostedFile != null && FileUpload1.PostedFile.FileName != "") {  
           // 10240 KB means 10MB, You can change the value based on your requirement  
                if (FileUpload1.PostedFile.ContentLength > 10240) {  
                           Page.ClientScript.RegisterClientScriptBlock(typeof(Page), "Alert", "alert('File is too big.')", true);  
                 }  else {  
                           //then save it to the Folder  
                           FileUpload1.SaveAs(Server.MapPath(imgPath));  
                           Image1.ImageUrl = "~/" + imgPath;  
                           Page.ClientScript.RegisterClientScriptBlock(typeof(Page), "Alert", "alert('Image saved!')", true);  
                }  
    
          }  
}  


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

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