在ASP .NET中有一个组合关系?

时间:2015-09-28 04:05:57

标签: list gridview datagridview

我有一辆由司机组成的汽车。我在gridview上显示任何信息时遇到问题。它只显示了Car的信息。在gridview上,我想显示如下:Car:Lancia Driver:Sandro,类似的东西。

以下是代码:

汽车:

[序列化]     公共类汽车     {         public String Brand {get;组; }         public String Model {get;组; }         public int Year {get;组; }         公共司机司机{得到;组; }

var_dump($this->headers);

驱动:

[序列化]     公共类司机     {         public String Name {get;组; }         public int Age {get;组; }         公共字符串国籍{get;组; }

    public Car(String Brand, String Model, int Year, Driver Driver)
    {
        Brand = Brand;
        Model = Model;
        Year = Year;
        Driver = Driver;
    }


    public Car()
    {
        Init();
    }

    public void Init()
    {
        Brand = string.Empty;
        Model = string.Empty;
        Year = 0;
        Driver = new Driver();
    }

aspx.cs:

public partial class WebForm1:System.Web.UI.Page     {

    public Driver(String Name, int Age, String Nationality)
    {
        Name = Name;
        Age = Age;
        Nationality = Nationality;

    }

    public Driver()
    {
        Init();

    }

    public void Init()
    {
        Name = string.Empty;
        Age = 0;
        Nationality = string.Empty;

    }

}

0 个答案:

没有答案