Click here to Skip to main content
15,885,278 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
XML
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);
 }
Posted
Comments
Orcun Iyigun 7-Jan-13 2:09am    
Do you use the magic tool called "Debugger"? Have you checked the values of that variable that you are having the exception from? Which line of the code you are having the exception? Let us know these. Dont expect us to be a physcic!!!
Sergey Alexandrovich Kryukov 7-Jan-13 2:23am    
It brings me to a good idea. We could create universal FAQ of very few questions like that and warn all inquirers that if they ask exact same question again, their post will be treated as spam. Honestly.

Very few questions like that, really. Incompatibility between type X and string (no implicit conversion), referencing null pointer, index out of range, maybe even the use of PictureBox for something dynamic/interactive...

—SA
Orcun Iyigun 7-Jan-13 2:38am    
Yeah Sergey, that sounds about right. We can create a FAQ like one default thing to do in these kind of particular situations. It surely will be beneficial but like as always there will be ignorant/typical members who will not take the time check that FAQ even it exists. Such people as "i need this code", "i want you to do my project"..etc.

So we should take that into consideration :) We can suggest this to Chris Maunder and if he approves I am in.
Sergey Alexandrovich Kryukov 7-Jan-13 2:52am    
Yes. And, by the way, this is a pretty usual practice. For example, if you use some publicly open issue management system access for some project, the "create ticked" action starts with the warning that the contributor to the tickets should first look for similar tickets; for this purpose, a search engine is provided. But we already have it, our goal is just to get rid of those copies of so frequent questions, those which have been repeated thousands of times...
—SA
Orcun Iyigun 7-Jan-13 5:10am    
I totally agree. I will post this as a suggestion under "Bugs&Suggestions" with your permission. Will you allow me to do it? :) or you take the lead and just do it?

1 solution

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.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 7-Jan-13 2:24am    
Sure, a 5.
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900