Click here to Skip to main content
15,891,253 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
DataRow[] drowpar = dt.Select("Parent_Id=" + 0);
      foreach (DataRow dr in drowpar)
      {
          MenuItem objMenuItem = new MenuItem();
          objMenuItem.Text = dr["Page_Name"].ToString();
          objMenuItem.NavigateUrl = dr["Page_Url"].ToString();
          MenuBar.Items.Add(objMenuItem);
      }
      foreach (DataRow dr in dt.Select("Parent_Id >" + 0))
      {
          MenuItem objMenuItem = new MenuItem();
          objMenuItem.Text = dr["Page_Name"].ToString();
          objMenuItem.NavigateUrl = dr["Page_Url"].ToString();
          //MenuBar.FindItem(dr["Parent_Id"].ToString()).ChildItems.Add(objMenuItem);
          MenuBar.FindItem(dr["Parent_Id"].ToString()).ChildItems.Add(objMenuItem);
          //MenuBar.Items.Add(objMenuItem);`
      }


i am binding asp.net menu control using database and getting this below in childitem binding to menu


Object reference not set to an instance of an object.

C#
MenuBar.FindItem(dr["Parent_Id"].ToString()).ChildItems.Add(objMenuItem);
Posted
Comments
JoCodes 28-Feb-14 11:58am    
Check whether dr["Parent_Id"] is null .

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