我想在没有图像的情况下在我的Repeater中放置带有“NO IMAGE”文字的图像。 我必须做出哪些改变才能实现这一目标?我希望我的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
答案 0 :(得分: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