Help! I get System.NullReferenceException

J

Jeff

hey

asp.net 2.0

The line "e.Item.Parent.ChildItems.Remove(e.Item);" gives this error:
'e.Item' threw an exception of type 'System.NullReferenceException'
System.Web.UI.WebControls.MenuItem {System.NullReferenceException}

The is the code where the exception occur:
protected void mnuSidebar_MenuItemDataBound(object sender, MenuEventArgs e)
{
string title = e.Item.Text;
if (title.Equals("Result"))
{
e.Item.Parent.ChildItems.Remove(e.Item);
}
}

This is part of my sitemap:
<siteMapNode url="~/Network.aspx" title="Network" description="" >
<siteMapNode url="~/Search.aspx" title="Search" description="" />
<siteMapNode url="" title="ItemA" description="" />
<siteMapNode url="" title="ItemB" description="" />
<siteMapNode url="" title="ItemC" description="" />
<siteMapNode url="~/Result.aspx" title="Result" description="" />
</siteMapNode>

mnuSidebar is a menu that only displays sub menu items ("Search", "ItemA",
"ItemB" etc)

What should I do to solve this problem?

Jeff
 
J

Jeff

I came across this tip:
protected void Menu1_MenuItemDataBound(object sender, MenuEventArgs e)
{
if (string.Equals(e.Item.DataPath, "/test/default.aspx",
StringComparison.InvariantCultureIgnoreCase))
{
Menu1.Items.Remove(e.Item);
}
}

and it solved my problem
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,982
Messages
2,570,186
Members
46,739
Latest member
Clint8040

Latest Threads

Top