0

当没有图像时,我想在我的中继器中放置带有文本“NO IMAGE”的图像。为了实现这一目标,我必须做出哪些改变?我希望我的中继器数据源指向我根目录中的 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
4

1 回答 1

1

如果没有图像,您可以只加载带有文本“No Images”的图像并将其添加到您的 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
于 2009-04-19T09:30:18.607 回答