将GridView绑定到对象列表(将对象列表作为属性)

时间:2020-02-19 12:42:01

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

我正在寻找一种将自定义类的列表(以列表作为属性)绑定到网格视图的可能性。

我的课:

public class SCE_ListItem
{
    public int ScE_ID { get; set; }
    public string SCE_Name { get; set; }       
    public string Level { get; set; }
    public string Speaker { get; set; }

    public List<Action> Actions { get; set; }
    public List<SCE_Products> Products { get; set; }
}


public class Action
{
    public int ID { get; set; }
    public string Description { get; set; }
    public string Runtime { get; set; }
    public string Activity { get; set; }
}


public class SCE_Products
{
    public int ScE_ID { get; set; }
    public XML_Files.Product Product { get; set; }
    public override string ToString()
    {
        return Product.Name;
    }
}

我要显示 SCE_ListItem 的所有属性,以及 Action类的所有信息,以及 SCE_Products

如果它将是仅具有原始数据类型的类,则可以使用

将其装箱到GridView中。
List<SCE_ListItem> listItems = SCE_ListItem.GetResultList();
gvResultList.DataSource = listItems;
gvResultList.DataBind();

但是由于有List和List,所以这些列不用于GridView。 有没有一种简单的方法,还是我必须通过遍历列表并为每个行添加列和行来绑定列表

0 个答案:

没有答案
相关问题