简体   繁体   English

在数据库Asp.net C#SQL中插入文件名时将图像上传到文件夹

[英]Uploading Image to folder while inserting filename in database Asp.net C# SQL

so started using a new method for dynamicly displaying images inserted into my database. 因此开始使用一种新方法动态显示插入到我的数据库中的图像。 This is the asp.net code 这是asp.net代码

<asp:ImageButton ID="ImageButton1" ImageUrl='<%#Eval ("ImageUrl", "~/img/{0}") %>' Width="200px" PostBackUrl='<%#Eval ("ProductID", "Product.aspx?ProductID={0}") %>' runat="server" />

now, as you can see what it does is getting the "ImageUrl" from my database depending on what the ProductID is, and then shows that as the image url. 现在,您可以看到它的作用是根据ProductID是什么从我的数据库中获取“ ImageUrl”,然后将其显示为图像URL。 Example in my folder /img/ i have a picture called "pic.jpg" then this code would make the image url "~/img/Pic.jpg" now how would i add a new image into the table from the backend? 在我的文件夹/ img /中的示例中,我有一张名为“ pic.jpg”的图片,那么此代码将使图像URL为“〜/ img / Pic.jpg”,现在我该如何从后端向表中添加新图像? i would have to make a flileupload control upload the file to the "img" folder and then insert only the file name as the "ImageUrl" in the database table. 我将必须使flileupload控件将文件上传到“ img”文件夹,然后在数据库表中仅插入文件名作为“ ImageUrl”。 How is this done? 怎么做? do you have any examples or can point me in the right direction? 你有什么例子或可以指出正确的方向吗?

thanks! 谢谢!

all answers appreciated! 所有答案表示赞赏!

ImageButton is actually a html input type image. ImageButton实际上是一个html输入类型的图像。 So you should not use it for just display purposes. 因此,您不应将其仅用于显示目的。 You can use Image control or even use html img tag. 您可以使用图像控件,甚至可以使用html img标签。

Check this link for FileUpload control 检查此链接以进行FileUpload控制

http://asp.net-tutorials.com/controls/file-upload-control/ http://asp.net-tutorials.com/controls/file-upload-control/

Check this link for Image control 检查此链接以进行图像控制

http://www.w3schools.com/aspnet/showaspx.asp?filename=demo_image http://www.w3schools.com/aspnet/showaspx.asp?filename=demo_image

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM