views:

259

answers:

1

I want to place a image with the text "NO IMAGE" in my Repeater when there is no image. What changes must i make in order to achieve this? I want my Repeater datasource to point to an image inside my IMAGE folder in my root directory.

My Page Load

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  A: 

In case of no images you can just load a image with text "No Images" and add it to your oList and assign it to 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
Ankit