2009-04-19 11 views
0

Ich möchte ein Bild mit dem Text "KEIN BILD" in meinem Repeater platzieren, wenn kein Bild vorhanden ist. Was muss ich ändern, um dies zu erreichen? Ich möchte, dass meine Repeater-Datenquelle auf ein Bild in meinem IMAGE-Ordner in meinem Stammverzeichnis zeigt.Ändern meiner Repeater-DataSource, wenn keine Objekte vorhanden sind

Meine Seite laden

If Not IsPostBack Then 

       Dim sBasePath As String = System.Web.HttpContext.Current.Request.ServerVariables("APPL_PHYSICAL_PATH") 
       If sBasePath.EndsWith("\") Then 
        sBasePath = sBasePath.Substring(0, sBasePath.Length - 1) 
       End If 

       sBasePath = sBasePath & "\" & "pics" & "\" & lblID.Text 

       Dim oList As New System.Collections.Generic.List(Of String)() 

       For Each s As String In System.IO.Directory.GetFiles(sBasePath, "*_logo.*") 

        'We could do some filtering for example only adding .jpg or something 
        oList.Add(System.IO.Path.GetFileName(s)) 

       Next 

       If oList.Count = 0 Then 

        //I must do something here 

        repImages.DataSource = ?????? 
        repImages.DataBind() 

       Else 

        repImages.DataSource = oList 
        repImages.DataBind() 

       End If 


      End If 

Antwort

1

Bei keine Bilder, die Sie gerade ein Bild mit Text „Keine Bilder“ laden, und fügen Sie es zu Ihrem olist und weisen

If Not IsPostBack Then 

      Dim sBasePath As String = System.Web.HttpContext.Current.Request.ServerVariables("APPL_PHYSICAL_PATH") 
      If sBasePath.EndsWith("\") Then 
       sBasePath = sBasePath.Substring(0, sBasePath.Length - 1) 
      End If 

      sBasePath = sBasePath & "\" & "pics" & "\" & lblID.Text 

      Dim oList As New System.Collections.Generic.List(Of String)() 

      For Each s As String In System.IO.Directory.GetFiles(sBasePath, "*_logo.*") 

       'We could do some filtering for example only adding .jpg or something 
       oList.Add(System.IO.Path.GetFileName(s)) 

      Next 

      If oList.Count = 0 Then 

       oList.Add("Path to a image with no image text") 

      End If 

    repImages.DataSource = oList 
       repImages.DataBind() 


     End If 
repImages.DataSource
Verwandte Themen