asp.net 数据绑定测试
时间:2011-01-30 来源:Jack.Wang
新建页面Student.aspx页面
public partial class Test_Student : System.Web.UI.Page { public class Student { public string Name { get; set; } public int Age { get; set; } } protected void Page_Load(object sender, EventArgs e) { var students = new[] { new Student{Name="mike",Age=23}, new Student{Name="jane", Age=12}, new Student{Name="frank",Age=25}, new Student{Name="susan",Age=32}, }; rptStudents.DataSource = students; DataBind(); } protected virtual TREsult ExpHelper<TEntity, TREsult>(Func<TEntity, TREsult> func) { var item = base.GetDataItem(); return func((TEntity)item); } protected TResult Eval<TResult>(Func<Student, TResult> func) { return ExpHelper<Student, TResult>(func); } } 在前台添加 <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> </head> <body> <form id="form1" runat="server"> <ul> <asp:Repeater ID="rptStudents" runat="server"> <ItemTemplate> <li> <%#Eval(n=>n.Age)%>---<%#Eval(n=>n.Name)%> </li> </ItemTemplate> </asp:Repeater> </ul> </form> </body></html>
相关阅读 更多 +