2009-04-19 26 views
0

我想在沒有圖像時在我的中繼器中放置帶有「無圖像」文本的圖像。 爲了實現這個目標,我必須做出什麼改變?我希望我的Repeater數據源指向我的根目錄中IMAGE文件夾內的圖像。當沒有圖像時,更改我的中繼器數據源

我的網頁加載

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 

回答

1

在沒有圖像的情況下,你只需要加載一個圖像與文字「沒有圖像」,並把它添加到您的oList並將其分配給repImages.DataSource

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