【问题标题】:Image is showing even in false if-else statement in c#.net即使在 c#.net 中的错误 if-else 语句中也显示图像
【发布时间】: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


【解决方案1】:

使用这个:

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

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

【讨论】:

  • 对不起,我对 c# 有点陌生,请问我应该在哪里声明可见性函数?
猜你喜欢
  • 2020-09-06
  • 1970-01-01
  • 2020-06-07
  • 2018-08-30
  • 2019-05-20
  • 1970-01-01
  • 2013-04-21
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多