FileUpload控制中的问题 [英] Problem in FileUpload Control

查看:95
本文介绍了FileUpload控制中的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用FileUpload控件,在提交uploadclick按钮之后.文件名保存在数据库中.然后在gridview中检索它的名称...在其中绑定图像按钮的地方吗?


问题是显示的是SubmitQuery而不是图像plz帮助...

 <   asp:imagebutton     id   ="    图片网址  ="  <%#Eval(" )%> " 命令名  ="   xmlns:asp    #unknown" / >  

解决方案

我不确定我是否正确理解了您的问题.假设您具有以下情况:

1.您正在使用FileUpload控件成功上传文件.
2.您可以将文件数据保存到数据库中(例如,文件名,大小等)

现在,当您尝试在网格视图"中显示图像"按钮时,您正在尝试将图像显示为图像"按钮的背景.但是,由于某些原因,没有为图像按钮显示图像.

如果以上理解是正确的,则需要进行以下操作:

一个重要的问题是,您将文件内容存储在哪里.在数据库中?或者,在文件系统中.

假设1:文件内容存储在文件系统中


-如果将文件内容存储在文件系统中,则对象的"picture"属性中的URL值应指向Web应用程序文件夹中的图像,或者使用一种方法将"picture"属性值作为参数并返回图像的相对URL.

例如,假设您将图像"profile.jpg" 作为"/images/profile.jpg" 存储在Web应用程序文件夹中.因此,对象的"picture"属性应包含URL "~/images/profile.jpg" ,或者可以按以下方式调用方法GetImageUrl():

Imageurl="<%# GetImageUrl(Eval ("picture")) %>"



其中方法willl仅采用"profile.jpg"作为参数,并返回"~/images/profile.jpg"

祝你好运

假设2:文件内容存储在数据库中


-在这种情况下,您需要做更多的工作.您必须如上所述提供ImageUrl property值,然后创建一个HttpHandler ,该HttpHandler 将处理在请求文件名中具有图像文件扩展名的任何URL,并在输出流中读写文件内容.

在此处查看HttpHandler示例: http://kurtschindler.net/blog/Post/Using- HttpHandlers-to-serv-image-files [ ^ ]


亲爱的,
您必须在解决方案中添加临时文件夹,并在RowDataBound事件上获得字节[]数据,该数据可以存储在HiddenField中,例如

<asp:hiddenfield id="hdfData" value="<%# Eval("ImageData")%>" xmlns:asp="#unknown" />



您可以在解决方案资源管理器中添加图像文件夹.通过在类后面的代码中实现server.map数学功能,可以在解决方案资源管理器中添加图像文件夹.
之后:

< asp:imagebutton id ="ImageButton1" runat ="server" imageurl =<%#"〜=" images =""=""+ =""eval(" picture)%& gt; "=""width =" 100px"height =" 100px"xmlns:asp ="#unknown> ;;


I am using FileUpload control, after submit of uploadclick button..the file name is saved in database.. and then I am reteriveing it in gridview ... where I bind image button?


Problem is that SubmitQuery is display instead of image plz help...

<asp:imagebutton id="ImageButton1" imageurl="<%# Eval(" picture=") %>" commandname="Image" xmlns:asp="#unknown" />

解决方案

I am not sure whether I understood your problem correctly. Assuming that you have the following situation:

1. You are uploading the file successfully using the FileUpload control.
2. You are able to save file data into database (Say, file name, size etc)

Now while you are trying to display the image button in the Grid View, you are trying to show the images as the Image button''s background. But, for some reason, the image is not being shown for the image buttons.

If the above understanding is correct, here is what you need to work on:

An important issue is, where are you storing the file content. In the database? Or, in the file system.

Assumption1 : File content is stored the file system


--If you are storing the file content in the file system, then, either in the "picture" property of your object should have a correct URL value that points to the image within the web application folder, or, you should use a method that takes the "picture" property value as parameter and returns the relative URL of the image.

For example, suppose you storing the image "profile.jpg" as "/images/profile.jpg" within the web application folder. so, either the "picture" property of your object should contain the URL "~/images/profile.jpg" or you can call a method GetImageUrl() as follows:

Imageurl="<%# GetImageUrl(Eval ("picture")) %>"



where the method willl take just the "profile.jpg" as parameter and will return "~/images/profile.jpg"

Good luck

Assumption2 : File content is stored in the database


--Well, in this case, you have to do a bit more work. You have to provide the ImageUrl property value as described above and then you have to create an HttpHandler that would handle any URL that has image file extension in the request file name and read and writes the file content in the output stream.

See an example HttpHandler here : http://kurtschindler.net/blog/Post/Using-HttpHandlers-to-serve-image-files[^]


Dear,
you have to add temporary folder in your solution and on RowDataBound Event you have to get byte[] data which could be stored in HiddenField like

<asp:hiddenfield id="hdfData" value="<%# Eval("ImageData")%>" xmlns:asp="#unknown" />



which is in gridview itemtemplate and retrieve in _RowDataBound Function.


you can add image folder in solution explorer.. with implementing server.map math function in code behind class..

after that :

<asp:imagebutton id="ImageButton1" runat="server" imageurl="<%# " ~="" images="" "="" +="" eval("picture")%&gt;"="" width="100px" height="100px" xmlns:asp="#unknown">;


这篇关于FileUpload控制中的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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