gridview 绑定list<实体类>
2014-08-26 17:22
417 查看
gridview 绑定list<实体类>是可以的,示例如一下。
<%@ Page Language="C#" %>
<%@ Import Namespace="System.Collections.Generic" %>
<script runat="server">
public class Employee
{
public int Id { get; set; }
public string Name { get; set; }
public Employee(int id, string name)
{
this.Id = id;
this.Name = name;
}
}
protected void Page_Load(object sender, EventArgs e)
{
List<Employee> list = new List<Employee>();
list.Add(new Employee(1, "Name1"));
list.Add(new Employee(2, "Name2"));
gv.DataSource = list;
gv.DataBind();
}
</script>
<!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>GridView 绑定 List 对象</title>
</head>
<body>
<form id="form1" runat="server">
<asp:GridView ID="gv" runat="server" />
</form>
</body>
</html>
<%@ Page Language="C#" %>
<%@ Import Namespace="System.Collections.Generic" %>
<script runat="server">
public class Employee
{
public int Id { get; set; }
public string Name { get; set; }
public Employee(int id, string name)
{
this.Id = id;
this.Name = name;
}
}
protected void Page_Load(object sender, EventArgs e)
{
List<Employee> list = new List<Employee>();
list.Add(new Employee(1, "Name1"));
list.Add(new Employee(2, "Name2"));
gv.DataSource = list;
gv.DataBind();
}
</script>
<!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>GridView 绑定 List 对象</title>
</head>
<body>
<form id="form1" runat="server">
<asp:GridView ID="gv" runat="server" />
</form>
</body>
</html>
相关文章推荐
- Gridview 绑定泛型List<T> 排序方法
- GridView绑定List<T>时要把自动生成行
- 遍历List<T>包含字典Dictionary和其他字段dataGridView绑定数据
- [测试]Gridview绑定SqlDataReader+IList<T>和SqlDataAdapter+DataSet的效率
- 如何判断List<Object>中是否包含,一个有相同xxx某个属性实体类
- DataTable转换为List<Model>的通用类(绑定Repeater智能提示)
- List<InvestInfoDO> invest = advertiseDao6.qryInvestInfo(InvestInfoDO1);怎样获得list的实体类;
- Mybatis无实体类,以List<Map<String,Object>>方式返回
- WinForm DataGridView 绑定泛型List(List<T>)/ArrayList不显示的原因和解决
- Winform中DataGridView绑定List<T>数据源时,点击DataGridView列头不能自动排序解决方法
- 泛型实体类List<>绑定到repeater
- 用List<T> 给 DataGridView 绑定数据时,无法正常显示
- GridControl 控件-----List<T>数据源 实现主从表关系绑定
- Dev GridView 绑定List<T>、BindingList <T>、BindingSource
- DataRow[]、List<DataRow>无法绑定到GridView的问题解决!
- List<T> 直接绑定到datagridview上不显示数据.
- Dev GridView 绑定List<T>、BindingList <T>、BindingSource
- DataGrid 绑定 字典集合 List<Dictionary<, >>
- 解决GridView绑定时无法将类型为 <>f__AnonymousType0`2[xx] 的对象强制转换为类型“xxx”的方法
- winform DataGridView绑定List<T>类型数据