Click here to Skip to main content
15,896,480 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
i have a list view :

ASP.NET
<asp:ListView ID="ListView1" runat="server">
          <ItemTemplate>
                <asp:ImageButton ID="ImageButton1" runat="server" />
          </ItemTemplate>
</asp:ListView>

and i have the link of the images in vb:

VB
Dim dirInfo As string="D:\rbi\images\emoticons\"
 Dim filenames As List(Of String) = dirInfo.GetFiles().[Select](Function(j) j.Name).ToList()


i'm getting the link and the filenames from the directory not from a database...so how can i bind these links in the list view to show all the images?
Posted

1 solution

Give this a look and see if it becomes a little clearer what you need to do.

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    Dim dirInfo As String = "c:\path\to\files\"

    Dim di As New IO.DirectoryInfo(dirInfo)
    Dim diar1 As IO.FileInfo() = di.GetFiles()
    Dim dra As IO.FileInfo

    Dim lvData As New List(Of FileObject)
    Dim ctr As Int32 = 0 ' used for FileID (optional)

    'loop all the files in the specified directory
    For Each dra In diar1
        lvData.Add(New FileObject With {.FileID = ctr + 1, .FileName = dra.Name})
    Next

    ListView1.DataSource = lvData
    ListView1.DataBind()

End Sub

Public Class FileObject
    Private _fileName As String
    Public Property FileName() As String
        Get
            Return _fileName
        End Get
        Set(ByVal value As String)
            _fileName = value
        End Set
    End Property
    Private _fileID As Int32
    Public Property FileID() As Int32
        Get
            Return _fileID
        End Get
        Set(ByVal value As Int32)
            _fileID = value
        End Set
    End Property
    ' additional properties as needed, file size, etc...
End Class
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900