J
Jeff
hi
asp.net 2.0
This code adds childmenuitems to a menuitem in a Menu controll. The problem
is that after the user has clicked on the menuitem, hence the shildmenuitems
are already added to the Menu control, If user again clicks on the menuitem,
then the childmenuitems get added again etc...
I want the code to works so that if childmenuitem already exists then don't
add it again
How can I avoid dublicates in this scenario?
protected void Menu1_Click(object sender, MenuEventArgs e)
{
int id = Convert.ToInt32(e.Item.Value);
List<Category> categories = Category.GetCategories(id);
if (categories.Count > 0)
{
foreach (Category cat in categories)
{
MenuItem item = new MenuItem();
item.Text = cat.Name;
item.Value = cat.Id.ToString();
e.Item.ChildItems.Add(item);
}
}
}
asp.net 2.0
This code adds childmenuitems to a menuitem in a Menu controll. The problem
is that after the user has clicked on the menuitem, hence the shildmenuitems
are already added to the Menu control, If user again clicks on the menuitem,
then the childmenuitems get added again etc...
I want the code to works so that if childmenuitem already exists then don't
add it again
How can I avoid dublicates in this scenario?
protected void Menu1_Click(object sender, MenuEventArgs e)
{
int id = Convert.ToInt32(e.Item.Value);
List<Category> categories = Category.GetCategories(id);
if (categories.Count > 0)
{
foreach (Category cat in categories)
{
MenuItem item = new MenuItem();
item.Text = cat.Name;
item.Value = cat.Id.ToString();
e.Item.ChildItems.Add(item);
}
}
}