我有一个列表集合,如下所示:
using System; using System.Collections.Generic; using System.Linq; using System.Web; namespace FileExplorer.Classes { public class NewAddedFiles { public string FileName; public string FilePath; public DateTime FileCreationDate; } }
private void GetFilesFromDirectory(string PhysicalPath) { DirectoryInfo Dir = new DirectoryInfo(PhysicalPath); FileInfo[] FileList = Dir.GetFiles("*.*",SearchOption.AllDirectories); List<NewAddedFiles> list = new List<NewAddedFiles>(); NewAddedFiles NewAddedFile = new NewAddedFiles(); foreach (FileInfo FI in FileList) { //Response.Write(FI.FullName); //Response.Write("<br />"); string AbsoluteFilePath = FI.FullName; string RelativeFilePath = "~//" + AbsoluteFilePath.Replace(Request.ServerVariables["APPL_PHYSICAL_PATH"],String.Empty); NewAddedFile.FileName = FI.Name; NewAddedFile.FilePath = RelativeFilePath; NewAddedFile.FileCreationDate = FI.CreationTime; list.Add(NewAddedFile); } Repeater1.DataSource = ????????????; Repeater1.DataBind(); }
我在aspx中的转发器如下所示:
<asp:Repeater ID="Repeater1" runat="server"> <ItemTemplate> <asp:Label ID="Label1" runat="server" Text='<%# Eval("FileName") %>'></asp:Label> <br /> <asp:Label ID="Label2" runat="server" Text='<%# Eval("FilePath") %>'></asp:Label> <br /> <asp:Label ID="Label3" runat="server" Text='<%# Eval("FileCreationDate") %>'></asp:Label> </ItemTemplate> </asp:Repeater>
如何将转发器数据源设置为List<>收集并使用它填充重复的标签?
编辑:
设置Repeater1.DataSource = list后出现错误
要么
在该中继器的Item_DataBound中添加一些代码,就像该答案一样
DataBinding: ‘FileExplorer.Classes.NewAddedFiles’ does not contain a
property with the name ‘FileName’.