我试图在 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;
}