本帖最后由 飘移 于 2012-10-10 05:26 编辑
作者官方的Demo中没有提供ext:Grid绑定集合对象的例子,这里我来提供一个ext:Grid绑定集合对象的例子,抛砖引玉,供初学者参考,高手可以略过:
以下代码放在cs代码文件中:
- protected class Student
- {
- public Student(int id, string name, string ent, bool ats, string major, int group, int gender, DateTime logtime, string desc, Guid guid, string hobby)
- {
- Id = id;
- Name = name;
- EntranceYear = ent;
- AtSchool = ats;
- Major = major;
- Group = group;
- Gender = gender;
- LogTime = logtime;
- Desc = desc;
- Guid = guid;
- Hobby = hobby;
- }
- public int Id { get; set; }
- public string Name { get; set; }
- public string EntranceYear { get; set; }
- public bool AtSchool { get; set; }
- public string Major { get; set; }
- public int Group { get; set; }
- public int Gender { get; set; }
- public DateTime LogTime { get; set; }
- public string Desc { get; set; }
- public Guid Guid { get; set; }
- public string Hobby { get; set; }
- }
- protected List<Student> GetStudents()
- {
- List<Student> students = new List<Student>();
- students.Add(new Student(101, "陈萍萍", "2000-9-1", true, "计算机", 1, 0, DateTime.Now.AddDays(-100), "陈萍萍,女,20岁,出生于中国南方的一个小山村,毕业于中国科学技术大学。", Guid.NewGuid(), "打游戏"));
- students.Add(new Student(102, "陈萍萍", "2000-9-1", true, "计算机", 1, 0, DateTime.Now.AddDays(-100), "陈萍萍,女,20岁,出生于中国南方的一个小山村,毕业于中国科学技术大学。", Guid.NewGuid(), "打游戏"));
- students.Add(new Student(103, "陈萍萍", "2000-9-1", true, "计算机", 1, 0, DateTime.Now.AddDays(-100), "陈萍萍,女,20岁,出生于中国南方的一个小山村,毕业于中国科学技术大学。", Guid.NewGuid(), "打游戏"));
- students.Add(new Student(104, "陈萍萍", "2000-9-1", true, "计算机", 1, 0, DateTime.Now.AddDays(-100), "陈萍萍,女,20岁,出生于中国南方的一个小山村,毕业于中国科学技术大学。", Guid.NewGuid(), "打游戏"));
- return students;
- }
- private void BindGrid()
- {
- Grid1.DataSource = GetStudents();
- Grid1.DataBind();
- }
复制代码
页面文件和官方的Grid Demo代码一致,不用特殊处理。
|