c# 中如何把实体类绑定到dataGridView并显示出来。
来源:百度知道 编辑:UC知道 时间:2024/05/11 01:12:53
将你的实体对象一个一个的加载进ArrayList对象中,在将ArrayList作为数据源绑定到datagridview空间里就行了.
注意:实体类必须每个字段属性话后才能作为绑定后的有效字段.
比如必须:
private int age= 0;
public int Age{ get{ return age;} } //必须实现get,这样数据集中就有Age这个字段了。
以下是我给你写的例子:
using System;
using System.Data;
public class Book
{
private string _Name = "";
public string Name
{
get { return _Name; }
set { _Name = value; }
}
private string _Title = "";
public string Title
{
get { return _Title; }
set { _Title = value; }
}
private int _Pages = 0;
public int Pages
{
get { return _Pages; }
set { _Pages = value; }
}
}
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;