类的实例中的数据绑定和列表

时间:2010-05-31 07:54:29

标签: c# asp.net data-binding datagrid

我初始化了一个名为“Relation”的类的实例,这个类还包含一个“Bills”列表。当我将这些信息数据绑定到网格时,关系正在显示,而比尔则没有。 Relation信息在List中返回,Bills在里面。

Relation cRelation = new Relation();
List<tRelation> relationList = cRelation.getRelations(); 

关系有:

relation.Bills <== List<tBills>;

如何确保列表中的列表也显示在Datagrid中?

2 个答案:

答案 0 :(得分:1)

你做不到。使用主/细节方法,这是一种方法:How to: Create Master/Detail Lists with the Windows Forms DataGrid Control

答案 1 :(得分:0)

将GridView放在网格的ItemTemplate中。

在第一个网格的 RowDataBound 上,获取每行的内部网格,并从源列表中应用数据绑定,如下所示:

Relation relation = (Relation) e.Row.DataItem;
GridView grdInner = (GridView) e.Row.FindControl("grdInner");
grdInner.DataSource = relation.Bills;
grdInner.DataBind();