图像甚至在 c#.net 中的错误 if-else 语句中显示

本文关键字:错误 语句 显示 if-else net 图像 | 更新日期: 2023-09-27 18:37:00

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

图像甚至在 c#.net 中的错误 if-else 语句中显示

使用这个:

Map.Visible = false;
MapImage.Visible = false;

如果可能的话,我建议对找到和未找到的图像使用相同的控件。