各位兄弟,我在网上下载了一个用户控件,是左侧导航栏的,但我调试以后发现有些问题,个人解决不了,向大家求救了。下载地址:http://download.csdn.net/detail/c9cad/6398061。按照原作者的的文件包,是可以运行的。但我添加了一个按钮,希望读取item的text时,就出错了。我在 LeftMenu.aspx.cs文件中增加了一个 protected void Button1_Click(object sender, EventArgs e)
{
this.TextBox1.Text= NavMenu1.ListItems[1].Items[1].Text;
}
点击之后报集合越界,找不到原因,请有时间的朋友帮我看看,谢谢大家。asp.net 导航调试控件
{
this.TextBox1.Text= NavMenu1.ListItems[1].Items[1].Text;
}
点击之后报集合越界,找不到原因,请有时间的朋友帮我看看,谢谢大家。asp.net 导航调试控件
NavMenu1.ListItems【1】。Items.Length
*****************************************************************************
http://feiyun0112.cnblogs.com/
this.TextBox1.Text = NavMenu1.ListItems.Count.ToString();
文本框显示“2”
这样数组越界了,我觉得应该是ListItems这里有问题,问题出在自定义控件里面,但我找不到原因啊。
public NavMenuItem this[int index]
{
get
{
return (NavMenuItem)_itemArrayList[index];
//return (NavMenuItem)List[index]; }
}
这个方法出了问题,但不知道怎么改
1、NavMenuItems.cs
using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;namespace HeroBeastControls.NavMenu
{
/// <summary>
/// NavMenu项集合操作
/// </summary>
public class NavMenuItems : CollectionBase
{
private ArrayList _itemArrayList;
public NavMenuItems()
{
_itemArrayList = new ArrayList();
}
public void Add(NavMenuItem _item)
{
List.Add(_item);
} public void Remove(NavMenuItem _item)
{
List.Remove(_item);
} public new int Count
{
get
{
return List.Count;
}
} public NavMenuItem this[int index]
{
get
{
return (NavMenuItem)_itemArrayList[index];
//return (NavMenuItem)List[index]; }
} }
}2、NavMenuItem.cs
using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using System.ComponentModel;
using System.Drawing.Design;
using System.Web.UI.Design;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;namespace HeroBeastControls.NavMenu
{
/// <summary>
/// Navigation Menu Item
/// </summary> [ParseChildren(true, "Items")]
[TypeConverter(typeof(NavMenuItemConverter))]
public class NavMenuItem
{ public NavMenuItem()
: this(String.Empty, String.Empty)
{
} public NavMenuItem(string cssname, string text)
{
CssClass = cssname;
Text = text;
}
/// <summary>
/// 项的样式
/// </summary>
private string _CssClass = "";
[
Category("Behavior"),
DefaultValue(""),
Description("项的样式"),
NotifyParentProperty(true)
]
public string CssClass
{
get { return _CssClass; }
set { _CssClass = value; }
} //private string _BackGroundImage;
//[UrlProperty("JPG文件(*.jpg)|*.jpg|PNG文件(*.png)|*.png|GIF文件(*.gif)|*.gif|所有文件(*.*)|*.*")]
//[Description("项的样式")]
//[Editor(typeof(UrlEditor), typeof(UITypeEditor))]
//public string BackGroundImage
//{
// get
// {
// return _BackGroundImage;
// }
// set
// {
// _BackGroundImage = value;
// }
//}
/// <summary>
/// 项文本
/// </summary>
private string _Text = "";
[
Category("Behavior"),
DefaultValue(""),
Description("项文本"),
NotifyParentProperty(true),
]
public string Text
{
get { return _Text; }
set { _Text = value; }
} /// <summary>
/// 定义项集合属性
/// </summary>
private NavMenuSubItems _ListItems;
[
Category("Behavior"),
Description("项集合"),
DesignerSerializationVisibility(
DesignerSerializationVisibility.Content),
PersistenceMode(PersistenceMode.InnerDefaultProperty),
Editor(typeof(NavMenuSubItemEditor), typeof(UITypeEditor))
]
public NavMenuSubItems Items
{
get
{
if (_ListItems == null)
{
_ListItems = new NavMenuSubItems();
}
return _ListItems;
}
}
}
}请高手帮忙看看
{
List.Add(_item);
} public void Remove(NavMenuItem _item)
{
List.Remove(_item);
}
public new int Count
{
get
{
return List.Count;
}
}
換成this.TextBox1.Text= NavMenu1.ListItems[0].Items[0].Text;試試呢?
你只加了一個ListItems?不知道ListItems起始Index是為0還是1
如图所示,NavMenuItems就是“系统设置”,“用户管理”,NavMenuItem应该就是“系统初始化”,“系统参数”。我现在想读取NavMenuItem,就是不成功。完整的源程序在:http://download.csdn.net/detail/c9cad/6398061,请各位老大有空帮忙看看!谢谢啦