Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/287.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 没有URL时如何隐藏图像控件?_C#_Asp.net - Fatal编程技术网

C# 没有URL时如何隐藏图像控件?

C# 没有URL时如何隐藏图像控件?,c#,asp.net,C#,Asp.net,我有一个中继器控制有图像控制有时这个图像控制没有数据,我想隐藏它,当它没有数据我做了代码,但它显示为图像没有数据(不可用)请任何人帮助我。 注意:数据来自数据库,所以Img有来自数据库的Id,但没有值(NULL) 是否该属性在某个位置被分配了空字符串?尝试改用字符串。IsNullOrEmpty: if (string.IsNullOrEmpty(Img.ImageUrl)) { Img.Visible = false; } 作为旁注,这可以缩短(选择最适合您的样式): 更好的方法是检索

我有一个中继器控制有图像控制有时这个图像控制没有数据,我想隐藏它,当它没有数据我做了代码,但它显示为图像没有数据(不可用)请任何人帮助我。
注意:数据来自数据库,所以Img有来自数据库的Id,但没有值(NULL)


是否该属性在某个位置被分配了空字符串?尝试改用
字符串。IsNullOrEmpty

if (string.IsNullOrEmpty(Img.ImageUrl))
{
    Img.Visible = false;
}
作为旁注,这可以缩短(选择最适合您的样式):


更好的方法是检索原始查询中用于填充中继器的徽标数据。然后,您将能够基于该数据在图像上设置Visible属性,而不必在绑定每一行时执行新的datbase查询。这将大大提高页面的性能

关于您发布的代码,您没有向SQLCommand传递图像id

   string Sql = "Select Logo From Model where ImageId = @ImageId";

   //Assuming List<ImageModel> is what you are binding to the repeater
   ImageModel model = e.Item.DataItem as ImageModel; 
   com.Parameters.Add("@ImageId", SqlDbType.Int32, model.ImageId);
string Sql=“从模型中选择徽标,其中ImageId=@ImageId”;
//假设列表是绑定到中继器的内容
ImageModel model=e.Item.DataItem作为ImageModel;
添加(“@ImageId”,SqlDbType.Int32,model.ImageId);

注意:数据来自数据库,所以Img有来自数据库的Id,但没有值(NULL)
Img.Visible = !string.IsNullOrEmpty(Img.ImageUrl);
   string Sql = "Select Logo From Model where ImageId = @ImageId";

   //Assuming List<ImageModel> is what you are binding to the repeater
   ImageModel model = e.Item.DataItem as ImageModel; 
   com.Parameters.Add("@ImageId", SqlDbType.Int32, model.ImageId);