对象引用未设置为对象C#WebForm的实例

时间:2019-03-12 09:39:31

标签: c#

我的webform申请存在问题。这种形式的错误对象引用未设置为对象的实例 异常详细信息:NullReferenceException

这是屏幕截图

enter image description here

这是我的代码

public void getDocument()
    {
        SessionHelper.Current.TemporaryDocument.Clear();
        List<ListItem> ListItemcblDocument = new List<ListItem>();
        foreach (ListItem item in cblDocument.Items)
        {
            ListItemcblDocument.Add(item);
        }
        cblDocument.Items.Clear();
        foreach (var items in SessionHelper.Current.TemporaryDetailCOB.ToList())
        {

            //new
            DMSDocumentSetting dsas = DocRepo.GetAllDocumentNewInq(items.IDCOB, true, null).FirstOrDefault();
            if (dsas != null)
            {
                List<DMSDocumentSettingDetail> dsa = DocRepo.getAllDetailDoc(dsas.IDDocumentSetting).ToList();
                foreach (var itemss in dsa)
                {
                    SessionHelper.Current.TemporaryDocument.Add(new V_DocumentViewModel
                    {
                        IDDocumentSettingDetail = itemss.IDDocumentSettingDetail,
                        COB = items.IDCOB,
                        DocumentSetting = itemss.DocumentSetting,
                        IDDocumentSetting = itemss.IDDocumentSetting,
                    });
                }
            }
        }

        foreach (var item in SessionHelper.Current.TemporaryDocument.ToList())
        {
            cblDocument.CellPadding = 30;
            cblDocument.CellSpacing = 30;
            cblDocument.RepeatColumns = 5;
            cblDocument.RepeatDirection = RepeatDirection.Horizontal;
            cblDocument.RepeatLayout = RepeatLayout.Table;
            cblDocument.TextAlign = TextAlign.Right;
            cblDocument.Items.Add(new ListItem(item.DocumentSetting, item.IDDocumentSettingDetail));
        }
        foreach (ListItem item in cblDocument.Items)
        {
            ListItem ListNew = ListItemcblDocument.FirstOrDefault(x => x.Text == item.Text && x.Value == item.Value);
            if (ListNew != null)
            {
                item.Selected = ListNew.Selected;
            }
        }

    }

您能从上面的代码中给出使NullException产生什么的原因吗?旁边有很多这样的例子 谢谢

0 个答案:

没有答案