c# - 根据下拉选择显示图像
问题描述
我有一个下拉列表,里面有医生名单。我想做的是当您从下拉列表中选择名称时,显示图像。
我遇到的问题是搜索图像文件夹并将其与从下拉列表中选择的名称进行比较。
这是我尝试在下面执行的操作,但不起作用:
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");
解决方案
我认为只需对您的代码稍作改动即可。一旦您从组合框或下拉列表中获取医生的姓名,我猜您将直接传递它以查找文件是否存在。
尝试这个 :-
string Name = "Parameter_SelectName";
string path = imgPath + Name + ".jpg"; //jpg being the extention of the pictures
bool fileExists = System.IO.File.Exists(path);
我希望这能解决问题。
推荐阅读
- flutter-web - 运行flutter web时如何指定端口号
- c++ - 计算偶数平均值时出现浮点异常错误
- java - 我可以在类中编辑休眠实体的字段(例如一些域逻辑)还是会导致一些与代理相关的问题?
- php - 成功提交表单和信息检索后如何加载Bootstrap modal?
- java - 如何访问随机跳转到恒定位置的二进制文件
- java - 如何修复尝试连接到 Java Swing 中的数据库的错误?
- python - Keras 应用程序 - imagenet 上的 VGG16 低精度
- python - ValueError:输入包含 NaN、无穷大或对于 dtype('float32') 来说太大的值。随机森林运行
- android-jetpack - 我正在尝试实现 NotificationChannel 和 WorkManager 但不知何故它不起作用并且没有看到任何错误
- python - 使用查找除数的函数,找到任意两个给定两个正整数的最大公约数