Click here to Skip to main content
12,752,634 members (36,011 online)
Rate this:
Please Sign up or sign in to vote.
See more: ASP.NET
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;
   //  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);

Posted 6-Jan-13 21:02pm
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!!!
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...

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.
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...
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?
Sure, please do it.
Pete O'Hanlon 8-Jan-13 5:25am
There's already a facility in place that could do this - create an article or tip/trick for the answer. There's no need for new functionality to accomplish what this site does amazingly well.
This is not what I mean, Pete, not at all. Please see again...
Pete O'Hanlon 8-Jan-13 9:33am
I know exactly what you meant, I'm not the thundering idiot you think I am and I'm perfectly capable of understanding what you were saying. However, there is already an excellent mechanism in place here on Code Project that is absolutely perfect for doing this, and would be of more benefit than just for the narrow scope of Q and A.
How can you get offended on nothing?! I simply did not have a minute to discuss it, nothing else...

If you think it's not useful, I don't want to argue, not sure myself, just discussing. I just say the
point is different: show something on every attempt to ask a question...


1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

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.
Sure, a 5.

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

    Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170217.1 | Last Updated 7 Jan 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100