后台CS代码:
namespace WebFormTest.TestCollect { public partial class ListTest : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { List<Person> list1 = new List<Person>(); list1.Add(new Person() { Age = 1, Name = "张三", Time = Convert.ToDateTime("2013/12/20 13:20") }); list1.Add(new Person() { Age = 5, Name = "李四", Time = Convert.ToDateTime("2013/12/20 14:20") }); list1.Add(new Person() { Age = 3, Name = "王五", Time = Convert.ToDateTime("2013/12/20 13:40") }); List<Person> list2 = new List<Person>(); list2.Add(new Person() { Age = 1, Name = "张三2", Time = Convert.ToDateTime("2013/12/20 13:20") }); list2.Add(new Person() { Age = 5, Name = "李四2", Time = Convert.ToDateTime("2013/12/20 14:20") }); list2.Add(new Person() { Age = 3, Name = "王五2", Time = Convert.ToDateTime("2013/12/20 13:40") }); list1 = list1.Concat(list2).ToList(); //合并多个list<T> list1 = list1.OrderByDescending(i => i.Time).ToList(); //降序排列 //list.OrderBy(i => i.Time);升序排列 Repeater1.DataSource = list1; Repeater1.DataBind(); } } public class Person { private int age; public int Age { get { return age; } set { age = value; } } private string name; public string Name { get { return name; } set { name = value; } } private DateTime time; public DateTime Time { get { return time; } set { time = value; } } } }
前台代码:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="ListTest.aspx.cs" Inherits="WebFormTest.TestCollect.ListTest" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title>无标题页</title> </head> <body> <form id="form1" runat="server"> <div> <table border="1" cellspacing="0" cellpadding="0" width="100%"> <asp:Repeater ID="Repeater1" runat="server"> <ItemTemplate> <tr> <td> <%#Eval("Age") %> </td> <td> <%#Eval("Name") %> </td> <td> <%#Eval("Time") %> </td> </tr> </ItemTemplate> </asp:Repeater> </table> </div> </form> </body> </html>
效果展示: