我從DHCP服務器的配置數據,我把成類是這樣的:嵌套類中的GridView
public class DHCP
{
public DHCP()
{
this.Scopes = new List<Scope>();
}
public List<Scope> Scopes;
public class Scope
{
public Scope(string ScopeAddress, string SubnetMask, string State, string ScopeName, string Comment)
{
this.ScopeAddress = ScopeAddress;
this.SubnetMask = SubnetMask;
this.State = State;
this.ScopeName = ScopeName;
this.Comment = Comment;
}
public Scope(string ScopeAddress, string SubnetMask, string State, string ScopeName, string Comment, bool initClients)
{
this.ScopeAddress = ScopeAddress;
this.SubnetMask = SubnetMask;
this.State = State;
this.ScopeName = ScopeName;
this.Comment = Comment;
if (initClients)
this.Clients = new List<Client>();
}
public void InitClients()
{
this.Clients = new List<Client>();
}
public void InitReservations()
{
this.Reservations = new List<Reservation>();
}
public string ScopeAddress { get; set; }
public string SubnetMask { get; set; }
public string State { get; set; }
public string ScopeName { get; set; }
public string Comment { get; set; }
public List<Client> Clients;
public List<Reservation> Reservations;
}
public class Client
{
public Client(string IPAddress, string SubnetMask, string UniqueID, string LeaseExpires, string ClientType)
{
this.IPAddress = IPAddress;
this.SubnetMask = SubnetMask;
this.UniqueID = UniqueID;
this.LeaseExpires = LeaseExpires;
this.ClientType = ClientType;
}
public string IPAddress { get; set; }
public string SubnetMask { get; set; }
public string UniqueID { get; set; }
public string LeaseExpires { get; set; }
public string ClientType { get; set; }
public Reservation ClientReservation { get; set; }
}
public class Reservation
{
public Reservation(string IPAddress, string UniqueID, bool ReservationActive)
{
this.IPAddress = IPAddress;
this.UniqueID = UniqueID;
this.ReservationActive = ReservationActive;
}
public string IPAddress { get; set; }
public string UniqueID { get; set; }
public string Name { get; set; }
public string Description { get; set; }
public string Type { get; set; }
public bool ReservationActive { get; set; }
}
}
然後,我有一個List<DHCP.Client>
,我在GridView上使用DataSource
。當我將其中一個數據字段設置爲ClientReservation.ReservationActive
時,我收到一個未找到的錯誤。
我試過這個列表<>這裏根本沒有NULL數據。 所以我必須問:
這可以完成嗎? 如果我有一個對象Client.ClientReservation == null
我該如何處理DataBind()
而不出錯?
是的我可以在代碼中使用myClient.ClientReservation,但不能作爲GridView控件中的綁定字段。這是我現在最大的問題。 –