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

<asp:ListView ID="ListView1" runat="server">
                <asp:ImageButton ID="ImageButton1" runat="server" />

and i have the link of the images in 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 how can i bind these links in the list view to show all the images?

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})

    ListView1.DataSource = lvData

End Sub

Public Class FileObject
    Private _fileName As String
    Public Property FileName() As String
            Return _fileName
        End Get
        Set(ByVal value As String)
            _fileName = value
        End Set
    End Property
    Private _fileID As Int32
    Public Property FileID() As Int32
            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