【问题标题】:How to hide Image controller?如何隐藏图像控制器?
【发布时间】:2015-05-23 10:12:14
【问题描述】:

我的页面中有五个图像控制器。如果他们没有任何图像,我想隐藏图像控制器。现在我得到了如下所示。

代码:

DataTable dt = new DataTable();
dt = tt.GetImage(Ids);
foreach (DataRow row in dt.Rows)
 {
   byte[] img1 = (byte[])row["Im1"];
   string base1 = Convert.ToBase64String(img1);
   Image1.ImageUrl = "data:image/jpg;base64," + base1;

   byte[] img2 = (byte[])row["Im2"];
   string base2 = Convert.ToBase64String(img2 );
   Image2.ImageUrl = "data:image/jpg;base64," + base2 ;

   byte[] img3 = (byte[])row["Im3"];
   string base3 = Convert.ToBase64String(img3 );
   Image3.ImageUrl = "data:image/jpg;base64," + base3 ;

   byte[] img4 = (byte[])row["Im4"];
   string base4 = Convert.ToBase64String(img4 );
   Image4.ImageUrl = "data:image/jpg;base64," + base4 ;

   byte[] img5 = (byte[])row["Im5"];
   string base5 = Convert.ToBase64String(img5 );
   Image5.ImageUrl = "data:image/jpg;base64," + base5 ;
 }

ASPX:

<asp:Image ID="Image1" runat="server" Width="559px" Height="210px"/>
<br />
<asp:Image ID="Image2" runat="server" Width="559px" Height="210px"/>
<br />
<asp:Image ID="Image3" runat="server" Width="559px" Height="210px"/>
<br />
<asp:Image ID="Image4" runat="server" Width="559px" Height="210px"/>
<br />
<asp:Image ID="Image5" runat="server" Width="559px" Height="210px"/>

【问题讨论】:

    标签: c# asp.net image


    【解决方案1】:

    看看这对你有没有帮助,我没有测试过。

            DataTable dt = new DataTable();
            dt = tt.GetImage(Ids);
    
            foreach (DataRow row in dt.Rows)
            {
                byte[] img1 = (byte[])row["Im1"];
                string base1 = Convert.ToBase64String(img1);
                Image1.ImageUrl = "data:image/jpg;base64," + img1;
                Image1.Visible = (!string.IsNullOrEmpty(base1));
    
                byte[] img2 = (byte[])row["Im2"];
                string base2 = Convert.ToBase64String(img2);
                Image2.ImageUrl = "data:image/jpg;base64," + base2;
                Image2.Visible = (!string.IsNullOrEmpty(base2));
    
                byte[] img3 = (byte[])row["Im3"];
                string base3 = Convert.ToBase64String(img3);
                Image3.ImageUrl = "data:image/jpg;base64," + base3;
                Image3.Visible = (!string.IsNullOrEmpty(base3));
    
                byte[] img4 = (byte[])row["Im4"];
                string base4 = Convert.ToBase64String(img4);
                Image4.ImageUrl = "data:image/jpg;base64," + base4;
                Image4.Visible = (!string.IsNullOrEmpty(base4));
    
                byte[] img5 = (byte[])row["Im5"];
                string base5 = Convert.ToBase64String(img5);
                Image5.ImageUrl = "data:image/jpg;base64," + base5;
                Image5.Visible = (!string.IsNullOrEmpty(base5));
            }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-07-13
      • 2016-02-22
      • 1970-01-01
      • 1970-01-01
      • 2018-08-04
      • 2016-06-28
      • 1970-01-01
      相关资源
      最近更新 更多