Click here to Skip to main content
12,070,351 members (50,955 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;
     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 6-Jan-13 21:02pm
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!!!
   
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.
   
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?
   
Sure, please do it.
—SA
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...
—SA
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...

—SA

1 solution

Rate this: bad
 
good
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.
  Permalink  
Comments
   
Sure, a 5.
—SA

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
Web04 | 2.8.160208.1 | Last Updated 7 Jan 2013
Copyright © CodeProject, 1999-2016
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