我有一个来自 DHCP 服务器的配置数据,我将其放入如下类中:
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>
我DataSource
在gridview上使用的。当我将其中一个数据字段设置为时,ClientReservation.ReservationActive
出现未找到错误。
我已经用 List<> 尝试过这个,这根本不是 NULL 数据。所以我不得不提问:
这完全可以做到吗?如果我有一个对象,Client.ClientReservation == null
我怎样才能在DataBind()
没有错误的情况下处理它?