首页 > 解决方案 > 根据下拉选择显示图像

问题描述

我有一个下拉列表,里面有医生名单。我想做的是当您从下拉列表中选择名称时,显示图像。

我遇到的问题是搜索图像文件夹并将其与从下拉列表中选择的名称进行比较。

这是我尝试在下面执行的操作,但不起作用:

string imgPath = "\\AccessExpress\ASPCode\OCUpgrade52\images";

if(Directory.Exists(imgPath)){

    string Name = Parameter_SelectName;//Contains the selection from drop down

    if(File.Exists(Path.Combine(imgPath, Name)) )
        Response.Write("true");
    else
        Response.Write("false");
}
else
    Response.Write("false");

收到以下错误:CS1009:无法识别的转义序列

并且很难抓取与要显示的选择相匹配的图像

更新:我能够通过以下方式解决问题(我希望这可以帮助遇到类似问题的其他人):

这是我到目前为止所拥有的:

string imgFolderPath = @"\\AccessExpress\ASPCode\OCUpgrade52\images";

bool folderExists = System.IO.Directory.Exists(imgFolderPath);

if(folderExists){
string urlPath = "http://oc2-reatest/OCUpgrade52/images/";
string imgName= Parameter_SelectName + ".png";
string img = string.Concat(urlPath,imgName);

bool fileExists = System.IO.File.Exists(System.IO.Path.Combine(imgFolderPath, imgName));

if(fileExists)
Response.Write("<img src='" + img + "' />");

else
Response.Write("File Does Not Exists");
}

else
Response.Write("Folder Does Not Exists");

标签: c#winforms

解决方案


我认为只需对您的代码稍作改动即可。一旦您从组合框或下拉列表中获取医生的姓名,我猜您将直接传递它以查找文件是否存在。

尝试这个 :-

            string Name = "Parameter_SelectName";
            string path = imgPath + Name + ".jpg"; //jpg being the extention of the pictures
            bool fileExists = System.IO.File.Exists(path);

我希望这能解决问题。


推荐阅读