• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 878
  • Last Modified:

Object reference not set to an instance of an object.


i am using the infragistics web tree controled and on my page load I am having  this error
Object reference not set to an instance of an object. the line that is causing it is below

igTree.Nodes[0].Selected =true ;

here is my page_load code
 protected void Page_Load(object sender, EventArgs e)
        if (!Page.IsPostBack)
            lblId.Text = Request["ParentTitle"];
            igTree.Nodes[0].Selected =true ;
         AdminID = Session["admin_id"].ToString();
2 Solutions
then either igTree or igTree.Nodes[0] is null.  Run it in the debugger and see which is null.  What is the code for LoadTree?
Yeah... it's likely that even if you are do a igTree = new 'WhatEverTheObjectNameIs'
that the nodes haven't been added the first time into the page.

Without seeing the code behind this.. I'd think that you will either need to add the node, first, OR make sure that the LoadTree function is working the way it's supposed to prior to setting the Selected value to true..

Simple check.. that may not provide the functionality you need long term would be to do something like this...

if( igTree != null && igTree.Nodes != null && igTree.Nodes.Count > 0 )
      igTree.Nodes[0].Selected =true ;

jemigossayeAuthor Commented:
okay thanks I had done some major damage to myself the loadtree was not retruning any values rather i wasn't retruning my dataset. what a day

thanks all
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now