title: I want to dynamically display submenu in asp .net
body: <p>I want to <code>display submenu dynamically from database</code>.But  I am getting an error in line
  menuBar. <code>FindItem(dr["ParentMenuId"].ToString()).ChildItems.Add(mnu);</code> that object reference not set to an instance of an object. also I am <code>unable to display my submenu</code>. What is the error please tell me.</p>
  
  <p>My code is:</p>
  
  <pre><code>protected void Page_Load(object sender, EventArgs e)
  {
      if (! IsPostBack)
          getMenu(); 
  }
  
  private void getMenu()
  {
      SqlConnection con = new SqlConnection(@"Data Source=ST015\SQLEXPRESS;Initial Catalog=MyData;Integrated Security=True");
      con.Open();
      DataSet ds = new DataSet();
      DataTable dt = new DataTable();
      string sql = "Select * from Categories";
      SqlDataAdapter da = new SqlDataAdapter(sql, con);
      da.Fill(ds);
      dt = ds.Tables[0];
     // DataRow[] drowpar = dt.Select("ParentMenuId=" + 0);
  
      foreach (DataRow dr in dt.Select("ParentMenuId=" + 0))
      {
          menuBar.Items.Add(new MenuItem(dr["MenuName"].ToString(),
                  dr["MenuId"].ToString(), "",
                  dr["MenuDescription"].ToString()));
      }
  
      foreach (DataRow dr in dt.Select("ParentMenuId &gt;" + 0))
      {
          MenuItem mnu = new MenuItem(dr["MenuName"].ToString(),
                         dr["MenuId"].ToString(),
                         "", dr["MenuDescription"].ToString());
          menuBar.FindItem(dr["ParentMenuId"].ToString()).ChildItems.Add(mnu);
  
      }
      con.Close();
  }
  </code></pre>
  
  <p>}</p>