本文介绍了菜单项的索引超出范围的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我有一个"System.ArgumentOutOfRangeException:索引必须在列表的范围内."例外.我想在Site.Master中创建一个菜单,该菜单可以在登录特殊用户时设置一个额外的Item.

Site.Master:

Hey all,

i have a "System.ArgumentOutOfRangeException: Index must be within the bounds of the List." exception. I want to create a menu in the Site.Master, which can set an extra Item when a special user is loged in.

Site.Master:

<div class="menu">
    <asp:Menu ID="Menu1" runat="server"

     EnableViewState="false"  

     Orientation="Horizontal" >
    
</div>



Site.Master.cs:



Site.Master.cs:

protected void Page_Load(object sender, EventArgs e)
{
       String User = Context.User.Identity.Name.Split(new Char[] { '\\' })[1];
       MenuItem item = new MenuItem();
       item.Text = "Configure";
       item.NavigateUrl = "~/Default.aspx";
       Menu1.Items.Add(item);
       if (User.Equals(user1) | User.Equals(user2))
       {
           item.Text = "Appstore";
           item.NavigateUrl = "~/AppStore.aspx";
           Menu1.Items.Add(item);
       }
       item.Text = "About";
       item.NavigateUrl = "~/About.aspx";
       Menu1.Items.Add(item);
}



有人可以告诉我怎么了吗?



Can someone tell me what´s wrong?

推荐答案

protected void Page_Load(object sender, EventArgs e)
{
       String User = Context.User.Identity.Name.Split(new Char[] { '\\' })[1];
       MenuItem item = new MenuItem();
       item.Text = "Configure";
       item.NavigateUrl = "~/Default.aspx";
       Menu1.Items.Add(item);
       if (User.Equals(user1) | User.Equals(user2))
       {
           item = new MenuItem();
           item.Text = "Appstore";
           item.NavigateUrl = "~/AppStore.aspx";
           Menu1.Items.Add(item);
       }
       item = new MenuItem();
       item.Text = "About";
       item.NavigateUrl = "~/About.aspx";
       Menu1.Items.Add(item);
}


这篇关于菜单项的索引超出范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-31 02:47