【发布时间】:2013-10-26 20:21:40
【问题描述】:
我试图在 c#.net 的 if-else 语句中显示图像。如果陈述为真,则显示图像,但如果陈述为假,则不应显示图像,但我的仍在显示图像。任何人都可以尽快帮助我。谢谢
if (dt.Rows.Count != 0)
{
DataRow dr = dt.Rows[0];
StatusLabel.Text = "Location Found!!";
StatusLabel.ForeColor = System.Drawing.Color.DarkGreen;
DescLabel.Text = dr["Description"].ToString();
String ImageFile = "Images\\" + dr["Image"];
Map.ImageUrl = ImageFile;
String ImageLoc = "IMap\\" + dr["MapImage"];
MapImage.ImageUrl = ImageLoc;
}
else
{
StatusLabel.Text = "Location not found in the database";
DescLabel.Text = "-";
StatusLabel.ForeColor = System.Drawing.Color.Red;
String NotFound = "NoImage\\th.jpg";
NoImage.ImageUrl = NotFound;
}
【问题讨论】:
-
那么它显示的是什么图像,在哪个控件中?请注意,对局部变量使用 PascalCase 非常令人困惑 IMO - 通常局部变量是驼峰式的。
-
it shouldnt show image是什么意思?将显示空图像控件或表示 NOIMAGE 或其他的特定图像? -
@JonSkeet 正如您在 else 语句中看到的那样,它显示“在数据库中找不到位置”。那是它应该显示未找到的图像名称的地方。但我的正在显示其他应该在 if 语句中显示的图像。
-
@HamletHakobyan 是的,它应该显示未找到的不同图像名称。但随后它显示了未找到的图像和图像 loc 本身。
-
应该显示图片还是显示文字?
标签: c# html asp.net image if-statement