Click here to Skip to main content
13,504,740 members
Rate this:
 
Please Sign up or sign in to vote.
i have a list view :

<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:

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 8-Nov-13 4:19am

1 solution

Rate this: bad
 
good
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})
    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
  Permalink  

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 |
Web01 | 2.8.180417.1 | Last Updated 8 Nov 2013
Copyright © CodeProject, 1999-2018
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