Click here to Skip to main content
13,260,330 members (40,360 online)
Rate this:
Please Sign up or sign in to 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?
Posted 8-Nov-13 5:19am

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

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

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web03 | 2.8.171114.1 | Last Updated 8 Nov 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100