menu控件 错误 索引必须位于该列表的界限内。 参数名: index
写网页的时候,在pageload时写了这么个代码
MenuItem i = new MenuItem();
Menu1.Items.Add(i);
Menu1.Items.Add(i);
public void Add(MenuItem child)
{
this.AddAt(this._list.Count, child);
}
public void AddAt(int index, MenuItem child)
{
if (child == null)
{
throw new ArgumentNullException("child");
}
if ((child.Owner != null) && (child.Parent == null))
{
child.Owner.Items.Remove(child);
}
if (child.Parent != null)
{
child.Parent.ChildItems.Remove(child);
}
if (this._owner != null)
{
child.SetParent(this._owner);
child.SetOwner(this._owner.Owner);
}
this._list.Insert(index, child);
this._version++;
if (this._isTrackingViewState)
{
((IStateManager) child).TrackViewState();
child.SetDirty();
}
this.Log.Add(new LogItem(LogItemType.Insert, index, this._isTrackingViewState));
}