问题描述
我正在使用asp.net菜单控件.
我无法删除超过2个子菜单项.我的索引超出范围.
但是,我在子菜单项中有6个以上的值..
为什么即使菜单计数中有该值,索引也会超出范围.
请给for循环删除每个子项...?
最近两个小时我在挣扎...?
看到我的错误代码
-----------------
I am using asp.net menu control.
i am not able to remove more than 2 child menu item. i am getting index out of range.
But, i have more than 6 values in the child menu items..
why i am getting index out of range even if the value is there in the menu count.
Pls. give the for loop to remove the every child item...?
i am getting struggle last two hours...?
see my error code
-----------------
For j As Integer = 0 To menuItemMaster.ChildItems.Count - 1 ==> 6 count will be there
If menuItemMaster.ChildItems(j).Value = "0" Then
menuItemMaster.ChildItems.Remove(menuItemMaster.ChildItems.Item(0))
End If
If menuItemMaster.ChildItems(j).Value = "2" Then
menuItemMaster.ChildItems.Remove(menuItemMaster.ChildItems.Item(2))
End If
If menuItemMaster.ChildItems(j).Value = "3" Then
menuItemMaster.ChildItems.Remove(menuItemMaster.ChildItems.Item(3))
End If
If menuItemMaster.ChildItems(j).Value = "4" Then
menuItemMaster.ChildItems.Remove(menuItemMaster.ChildItems.Item(4)) ==> Error : out of index range
End If
Next
推荐答案
For j As Integer = 0 To menuItemMaster.ChildItems.Count - 1 ==> 6 count will be there
If menuItemMaster.ChildItems(j).Value = "0" Then
menuItemMaster.ChildItems.Remove(menuItemMaster.ChildItems[j].Item(0))
End If
If menuItemMaster.ChildItems(j).Value = "2" Then
menuItemMaster.ChildItems.Remove(menuItemMaster.ChildItems[j].Item(2))
End If
If menuItemMaster.ChildItems(j).Value = "3" Then
menuItemMaster.ChildItems.Remove(menuItemMaster.ChildItems[j].Item(3))
End If
If menuItemMaster.ChildItems(j).Value = "4" Then
menuItemMaster.ChildItems.Remove(menuItemMaster.ChildItems[j].Item(4)) ==> Error : out of index range
End If
Next
我已经改变了
menuItemMaster.ChildItems.Remove(menuItemMaster.ChildItems.Item(3))到 menuItemMaster.ChildItems.Remove(menuItemMaster.ChildItems [j] .Item(3))
希望这会对您有所帮助
I have changed
menuItemMaster.ChildItems.Remove(menuItemMaster.ChildItems.Item(3)) to menuItemMaster.ChildItems.Remove(menuItemMaster.ChildItems[j].Item(3))
Hope this will help you out
这篇关于如何在asp.net菜单控件中使用for循环删除子项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!