从目录中列出视图中的数据 [英] binding data in a list view from a directory
本文介绍了从目录中列出视图中的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个列表视图:
i have a list view :
<asp:ListView ID="ListView1" runat="server">
<ItemTemplate>
<asp:ImageButton ID="ImageButton1" runat="server" />
</ItemTemplate>
</asp:ListView>
我在vb中有图像的链接:
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?
推荐答案
看一看,看看它是否更清楚你需要做什么。
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
这篇关于从目录中列出视图中的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文