如何在ASP.NET中使用列表集合作为Repeater数据源与C#
发布时间:2020-05-24 09:06:05 所属栏目:asp.Net 来源:互联网
导读:我有一个列表集合,如下所示: using System;using System.Collections.Generic;using System.Linq;using System.Web;namespace FileExplorer.Classes{ public class NewAddedFiles { public string FileNam
|
我有一个列表集合,如下所示: 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<>收集并使用它填充重复的标签? 编辑:
解决方法只需将您的列表设置为DataSource:Repeater1.DataSource = list; 编辑 您没有实际的属性,您正在使用字段.您需要创建实际属性才能使数据绑定找到它们. 所以修改你的类,如: public class NewAddedFiles
{
public string FileName { get; set; }
public string FilePath { get; set; }
public DateTime FileCreationDate { get; set; }
} (编辑:安卓应用网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- asp.net-mvc – 自定义控制器工厂,依赖注入/结构图问题与AS
- asp.net – NavigateUrl =“#”变成href =“SubFolder /#”
- asp.net – web.config不转发到非.aspx页面上的404错误页面
- asp.net – 将自定义类添加到HttpContext
- asp.net-mvc-3 – 剃刀引擎 – 如何根据不同的条件渲染不同
- asp.net-mvc – 直接下载链接到ASP.NET MVC 5 for VS 2012
- asp.net-mvc – automapper,你在哪里放置代码将View Model映
- 文件上传 – 以经典的asp上传文件
- asp.net-mvc-3 – 如何根据当前页面和/或主页在Orchard CMS
- ASP.NET 5中的全局异常处理
推荐文章
站长推荐
- 在asp.net mvc中的RedirectToAction用法
- asp.net-mvc – 域模型中的ASP.NET MVC业务逻辑与
- asp.net-mvc – 从一个项目到另一个项目调用控制
- asp.net – “localhost”上运行网站是非常慢
- asp.net – 如何通过web.config文件中的Access-C
- asp.net-mvc – Html.HiddenFor值属性未设置
- asp.net – 在web.config location元素中无法识别
- asp.net-mvc – AntiForgeryToken在ASP.Net MVC
- 如何排序. .NET中的resx(资源文件)
- asp.net – N层和SOA架构有什么区别?
热点阅读
