【问题标题】:How to Retrieve File Path from SQL Server Database and Display Image in Image Control如何从 SQL Server 数据库中检索文件路径并在图像控件中显示图像
【发布时间】:2016-11-15 20:05:05
【问题描述】:

我的 ASP.NET C# 项目中有一个 Images 文件夹。

我将此文件夹的文件路径存储在 SQL Server 数据库的图像表中。

我想在图像控件中显示图像,该图像应根据我在下拉控件中选择的内容进行更改。

我已经能够使用图像名称填充下拉菜单,但我不知道如何选择图像,因为它们包含在上述文件夹中。

【问题讨论】:

  • 你能提供代码吗?
  • 为什么不直接设置检索到的 ImageUrl = Path?

标签: c# asp.net sql-server


【解决方案1】:

首先你需要找到你的根目录

  string root = Server.MapPath("~");

像这样将它附加到您的文件夹中

 string path = root + "assets\\images\\products\\";

然后将其与您的文件名连接起来。

string FileName = path+dd.SelectedItem;

并更改 ImageControl

使用 dropdownselectedindexchanged 事件并设置

IMGCTRL.ImageURL=FileName;

【讨论】:

    猜你喜欢
    • 2014-02-28
    • 1970-01-01
    • 1970-01-01
    • 2014-10-02
    • 2019-01-05
    • 2023-03-24
    • 2018-11-08
    • 2021-03-05
    • 1970-01-01
    相关资源
    最近更新 更多