本例和 使用ObjectDataSource----显示业务对象 的差别就是:
1、//PersonManager.cs变为:
using System;
using System.Web;
public class PersonManager ...{
private const string personsKey = "persons";
public PersonCollection SelectPersons() ...{
HttpContext context = HttpContext.Current;
if (context.Application[personsKey] == null) ...{
PersonCollection persons = new PersonCollection();
persons.Add(new Person(0, "Patrick", "Lorenz"));
persons.Add(new Person(1, "Micha", "Brunnhuber"));
persons.Add(new Person(2, "Thomas", "Ballmeier"));
context.Application[personsKey] = persons;
}
return (context.Application[personsKey] as PersonCollection);
}
public Person SelectPerson(int id) ...{
return this.SelectPersons().FindPersonById(id);
}
}
2、GridView改用DetailsView
最后效果:
参考《ASP.NET 2.0 大揭密 》