开发者

Databinding and Lists in instances of classes

开发者 https://www.devze.com 2023-01-01 09:12 出处:网络
I have initialised an instance of a class i have called \"Relation\" this class also contains a list of \"Bills\". When i databind this information to a grid, the Relations are showing, tho the Bills

I have initialised an instance of a class i have called "Relation" this class also contains a list of "Bills". When i databind this information to a grid, the Relations are showing, tho the Bills ain't. The Relation information is returning in a List and the Bills are inside.

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

a relation has:

relation.Bills <== List<tBills>;

How to 开发者_开发百科make sure that the list inside the list is also getting showed in the Datagrid?


You can't. Use a Master/Detail approach for this, Here's one approach: How to: Create Master/Detail Lists with the Windows Forms DataGrid Control


Put a GridView inside an ItemTemplate of your grid.

On RowDataBound of your first grid, get the inner grid for each row and apply databinding from the source list as follows:

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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号