2016-11-15 89 views
0

我的ASP.NET C#项目中有一个Images文件夹。如何从图像控件中检索SQL Server数据库和显示图像的文件路径

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

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

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

+0

你能提供的代码? – Usman

+0

为什么你不设置你检索的ImageUrl = Path? –

回答

0

首先,你需要通过

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

找到自己的根目录与您的文件夹追加像这样

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

然后用您的文件名串连它。

string FileName = path+dd.SelectedItem; 

并改变ImageControl

使用dropdownselectedindexchanged事件,并

IMGCTRL.ImageURL=FileName; 
相关问题