在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
看了这篇文章后写出的笔记 http://www.cnblogs.com/dragonpig/archive/2011/01/29/1947648.html 就是这样虽然有了智能提示,但是反应很慢,有时候需要编译几次才会正确,这种改造方法有点像mvc,都是lambda表达式,这里记录下方法。 using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; namespace Asp.net.bind.data { public partial class WebForm1 : System.Web.UI.Page { 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; rptStudents.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); } } } view : <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="Asp.net.bind.data.WebForm1" %> <!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 > <asp:Repeater ID="rptStudents" runat="server"> <ItemTemplate> <li> <%#Eval(m => m.Name)%></li> </ItemTemplate> </asp:Repeater> </form> </body> </html> |
请发表评论