【发布时间】:2017-10-18 09:42:33
【问题描述】:
我试图在选择图像然后将其保存到数据库后在网站上显示图像。 C# .aspx
<td ><strong>Product Photograph</strong></td>
<td ><asp:FileUpload runat="server" ID="FileUpload1"/>
<asp:Button ID="btnUpload" runat="server" Text="Upload" OnClick="Upload" />
<asp:Image ID="Image1" runat="server" />
</td>
c#
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
string[] filePaths = Directory.GetFiles(Server.MapPath("~/Images/"));
List<ListItem> files = new List<ListItem>();
foreach (string filePath in filePaths)
{
string fileName = Path.GetFileName(filePath);
files.Add(new ListItem(fileName, "~/Images/" + fileName));
}}
}
我不知道如何附加选择的 ID="Image1" 图像。任何帮助将不胜感激。
【问题讨论】: