总是一到 bill.item.Add(billitem);这里就报“未将对象引用设置到对象的实例”。
代码如下:
public class StoreBill
{
/// <summary>
/// ID
///// </summary>
public int ID { get; set; }
/// <summary>
/// 商品集合
/// </summary>
private List<StoreBillItem> _Items = new List<StoreBillItem>();
public List<StoreBillItem> item { get; set; }
}
谢谢各位了!
Goods gd = new Goods();
StoreBill bill = new StoreBill();
StoreBillItem billitem = new StoreBillItem();
for (int i = 0; i < gridView1.RowCount; i++)
{
gd.ID = int.Parse(i.ToString() + "123");
gd.Code = gridView1.GetRowCellValue(i, "Code").ToString();
gd.Name = gridView1.GetRowCellValue(i, "Name").ToString();
gd.Scole = int.Parse(gridView1.GetRowCellValue(i, "Scole").ToString());
gd.Price = decimal.Parse(gridView1.GetRowCellValue(i, "Price").ToString());
billitem.ID = int.Parse(i.ToString() + "456");
billitem.Code = gridView1.GetRowCellValue(i, "Code").ToString();
billitem.Name = gridView1.GetRowCellValue(i, "Name").ToString();
billitem.Scole = int.Parse(gridView1.GetRowCellValue(i, "Scole").ToString());
billitem.Price = decimal.Parse(gridView1.GetRowCellValue(i, "Price").ToString());
bill.item.Add(billitem);
}
------解决思路----------------------
你的item又没用那个带下划线的私有字段,那个倒是new了的,然后get set的呢没有实例化,当然报异常了
------解决思路----------------------
private List<StoreBillItem> _Items = new List<StoreBillItem>();
public List<StoreBillItem> item { get{return _Items;} }
------解决思路----------------------
private List<StoreBillItem> _Items = new List<StoreBillItem>();
public List<StoreBillItem> item { get{return _Items;} }