1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Web;
5 using System.Web.UI;
6 using System.Web.UI.WebControls;
7
8 public partial class demo : System.Web.UI.Page
9 {
10 protected void Page_Load(object sender, EventArgs e)
11 {
12 this.Repeater1.DataSource = this.GetList();
13 this.Repeater1.DataBind();
14 }
15
16 public IList<Student> GetList()
17 {
18 IList<Student> list = new List<Student>();
19 list.Add(new Student("张三", 22));
20 list.Add(new Student("李四", 25));
21 return list;
22 }
23 }
24
25
26 public class Student
27 {
28 public Student(string _Name, int _Age)
29 {
30 this.Name = _Name;
31 this.Age = _Age;
32 }
33 public string Name
34 {
35 set;get;
36 }
37 public int Age
38 {
39 set;get;
40 }
41 }
42
43 public static class Binder<TEntity> where TEntity : class
44 {
45 public static TResult Eval<TResult>(System.Web.UI.Page p, Func<TEntity, TResult> func)
46 {
47 return func((TEntity)p.GetDataItem());
48 }
49 }
1 <%@ Page Language="C#" AutoEventWireup="true" CodeFile="demo.aspx.cs" Inherits="demo"%>
2
3 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
4 <html xmlns="http://www.w3.org/1999/xhtml">
5 <head runat="server">
6 <title></title>
7 </head>
8 <body>
9 <form id="form1" runat="server">
10 <div>
11 <asp:Repeater ID="Repeater1" runat="server">
12 <ItemTemplate>
13 姓名:<%#Binder<Student>.Eval(this,n=>n.Name) %>
14 年龄:<%#Binder<Student>.Eval(this,n=>n.Age) %><br />
15 </ItemTemplate>
16 </asp:Repeater>
17 </div>
18 </form>
19 </body>
20 </html>
上面是一个页面的代码,可以运行成功!
1、如何应用到多表查询时的强类型绑定?
2、如何应用到绑定的是DataTable数据源?
能解决DataTable那个多表查询的就解决了,如何解决,等待答案中……
看到博客http://kb.cnblogs.com/page/90080/留下的疑问
你可以多表对应一个对象啊,
public class Student
27 {
28 public Student(string _Name, int _Age)
29 {
30 this.Name = _Name;
31 this.Age = _Age;
32 }
33 public string Name
34 {
35 set;get;
36 }
37 public int Age
38 {
39 set;get;
40 }
41 }
如果你有一个分数表,你可以把分数对象类当做属性写在Student中,再数据库的数据绑定在这个Student对象中就可以了。
你在Model里面添加一个类啊! 然后添加的view的时候直接选择者个类型就行了 啊
如何应用到多表查询时的强类型绑定?
你在Model类创建一个类啊 把你要查询的属性 都添加进去啊 虽然这个方法比较笨 但还是可以解决问题啊
是要把Ilist数据类型转换成DataTable吗?