预期结束

时间:2011-10-12 10:27:25

标签: asp.net vb.net

Imports System
Imports System.IO
Imports System.Linq

Namespace PhotoGalleryApp
    Partial Public Class Index
        Inherits System.Web.UI.Page

        Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
            ' Path to photos folder
            Dim photosRelativePath = "~/photos/"
            Dim photosFilePath = Me.Server.MapPath(photosRelativePath)

           ' Get list of img files from photos folder
            Dim photos = From file In New DirectoryInf(photosFilePath).GetFiles() 
            Where (file.Name.EndsWith(".jpg",
                                StringComparison.InvariantCultureIgnoreCase)
                   OrElse file.Name.EndsWith(".gif",
                                StringComparison.InvariantCultureIgnoreCase)
                   OrElse file.Name.EndsWith(".png",
                                StringComparison.InvariantCultureIgnoreCase))
            Select photosRelativePath & file.Name

            ' Return photos as string array
            lstPhotos.DataSource = photos.ToArray()
            lstPhotos.DataBind()
        End Sub
    End Class
End Namespace

我将此代码用于jQuery Cycle Plugin。

这是aspx代码

 <asp:ListView ID="lstPhotos" runat="server">
        <ItemTemplate>
            <img src='<%# ResolveUrl(Container.DataItem.ToString()) %>' width="250" height="300" />
        </ItemTemplate>
        </asp:ListView>


    <script type="text/javascript" src="http://ajax.microsoft.com/ajax/jquery/jquery-1.4.2.js"></script> 
    <script type="text/javascript" src="http://ajax.microsoft.com/ajax/jquery.cycle/2.88/jquery.cycle.all.js"></script> 
    <script type="text/javascript">

        $("#photos").cycle("toss");

    </script> 

我在后面的代码中将LIstView的DataSource设置为Photos.ToArray()但仍然出现错误..“为ListView选择DataSource”

1 个答案:

答案 0 :(得分:0)

尝试替换

Dim photos = From file In New DirectoryInfo(photosFilePath).GetFiles() 
                Where (file.Name.EndsWith(".jpg", 
                             StringComparison.InvariantCultureIgnoreCase) 
                           OrElse 
                       file.Name.EndsWith(".gif", 
                             StringComparison.InvariantCultureIgnoreCase) OrElse 
                       file.Name.EndsWith(".png", 
                             StringComparison.InvariantCultureIgnoreCase)) 
                       photosRelativePath & file.Name

Dim photos = From file In New DirectoryInfo(photosFilePath).GetFiles() 
                Where (file.Name.EndsWith(".jpg", 
                             StringComparison.InvariantCultureIgnoreCase) OrElse
                       file.Name.EndsWith(".gif", 
                             StringComparison.InvariantCultureIgnoreCase) OrElse 
                       file.Name.EndsWith(".png", 
                             StringComparison.InvariantCultureIgnoreCase)) 
                       select photosRelativePath & file.Name