在Datalist Control中对图片进行排序

时间:2012-01-23 04:58:40

标签: vb.net datalist

我有一个Datalist控件并从文件夹中读取图片并在Datalist的灯箱中显示它们我也在从这些图片中读取数据和时间。我的事情是数据列表没有读取从属性中获取的日期图片和第二个是图片没有按照日期拍摄的顺序排序。请任何人告诉我如何完成这些任务。 我的数据列表代码在这里

<asp:DataList ID="DataList1" runat="server" RepeatColumns="5" RepeatDirection="Horizontal" Width="23%" CellPadding="2" CellSpacing="0" Height="270px" HorizontalAlign="Center">

<ItemTemplate>
<asp:Image Width="200px" height="200px" ID="Image1" ImageUrl='<%# Bind("Name", "~/MMS/1 Box/{0}") %>' runat="server" />
<br />

<asp:HyperLink ID="HyperLink1" rel="lightbox[roadtrip]" title='<%# DataBinder.Eval(Container.DataItem, "LastWriteTime", "{0:yyyy-MM-dd   hh:mm:ss}") %>'
 Text="Zoom" NavigateUrl='<%# Bind("Name", "~/MMS/1 Box/{0}") %>' runat="server"/>
</ItemTemplate>
<ItemStyle BorderColor="Silver" BorderStyle="Dotted" BorderWidth="1px" HorizontalAlign="Center"

VerticalAlign="Bottom" />
</asp:DataList>

并从文件夹中读取图像我的vb.net代码在这里

Sub loadimage()
        Dim sdir As New DirectoryInfo(MapPath("~/MMS/1 Box"))

        Dim file As FileInfo() = sdir.GetFiles()
        Dim list As New ArrayList()

        For Each file2 As FileInfo In file
            If file2.Extension = ".jpg" OrElse file2.Extension = ".gif" OrElse file2.Extension = ".bmp" Then

                list.Add(file2)

            End If

        Next

        DataList1.DataSource = list

        DataList1.DataBind()


    End Sub

任何人都告诉我应该在代码中做出哪些更改,以便我的两个要求也将完成

1 个答案:

答案 0 :(得分:0)

使用IComparable根据时间创建时间或您要对其进行排序的任何属性对列表进行排序。

以下链接可帮助您实现此目的:http://www.knowdotnet.com/articles/sortarraylistofobjects.html