using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.MobileControls; namespace DataBindEx { public class Person { public string FirstName { get; set; } public string SecondName { get; set; } public string FullName { get { return FirstName + SecondName; } } } public partial class _Default : System.Web.UI.Page { public string Property { get { return "This is a Property"; } } protected void Page_Load(object sender, EventArgs e) { string str = TextBox1.Text; Person per = new Person(); per.FirstName= "刘"; per.SecondName= "明丰"; Person per1 = new Person(); per1.FirstName = "林"; per1.SecondName = "旺"; Person per2 = new Person(); per2.FirstName = "陈"; per2.SecondName = "仁峰"; List<Person> list = new List<Person>(); list.Add(per); list.Add(per1); list.Add(per2); Repeater1.DataSource = list; Repeater1.DataBind(); } protected void RptAllOnItemDataBound(object sender, RepeaterItemEventArgs e) { Person pe = (Person)e.Item.DataItem; Literal lit = e.Item.FindControl("Others") as Literal; if (pe !=null) switch (pe.FirstName) { case "刘": lit.Text = "刘喜欢打球"; break; case "林": lit.Text = "林喜欢下棋"; break; default: lit.Text = "陈喜欢c#"; break; } } protected string Method() { return "This is a Method"; } } }