对象引用设置为object的实例 [英] Object reference is set to instance of object

查看:69
本文介绍了对象引用设置为object的实例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

protected void listPOItems_OnItemEditing(object sender, System.Web.UI.WebControls.ListViewEditEventArgs e)
 {
     listPOItems.EditIndex = e.NewEditIndex;
     qcpackingitemscollections objItems = new qcpackingitemscollections();
     if (Session["StoresIndentItemCollection"] != null)
         objItems = (qcpackingitemscollections)Session["StoresIndentItemCollection"];

     listPOItems.DataSource = objItems;
     listPOItems.DataBind();
   //  BindEditDDLs();
   //  DropDownList ddlMate = (DropDownList)listIndentItems.Items[e.NewEditIndex].FindControl("ddlMaterials");
     TextBox txtseno = (TextBox)listPOItems.Items[e.NewEditIndex].FindControl("txtseno");
     List<PackingInstructionItem> objIndentItemCollection = new List<PackingInstructionItem>();
     if (Session["StoresIndentItems"] != null)
         objIndentItemCollection = (List<PackingInstructionItem>)Session["StoresIndentItems"];

     var selVal = objIndentItemCollection.Where(i => i.ItemId == e.NewEditIndex + 1).Single();
// The below line Object reference is set to instance of object error will occured//
     txtseno.Text =Convert.ToString( selVal.SerialNo);

    ScriptManager.GetCurrent(this).SetFocus(txtseno);
 }

推荐答案

当您尝试访问对象的属性为null时,会发生此错误。



尝试调试并逐步查看源代码。

它肯定会帮助您找出错误发生的位置,然后您可以根据需要应用修复程序。



最有可能的原因是您尝试访问的Session对象,例如 Session [StoresIndentItemCollection] null
This error occurs when you try and access an attribute of an object that is null.

Try debugging and step though your source code.
It will surely help you find out where the error occurs and then you can apply a fix as appropriate.

Most likely cause is that the Session objects that you are trying to access e.g. Session["StoresIndentItemCollection"] are null.


这篇关于对象引用设置为object的实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆