我有一个菜单,该菜单在我的主页上具有子菜单。当菜单打开第二个窗口时,我想知道用户选择了哪个选项。例如:顶层菜单是“编辑现有项目”。子选项为“修改项目状态;修改项目描述;修改项目HTS代码。
过去7个小时里,我几乎尝试过每篇文章和建议。
在网站主站点上:
<asp:Menu ID="NavigationMenu0" runat="server" CssClass="auto-style7"
EnableViewState="False" IncludeStyleBlock="False"
Orientation="Horizontal"
Height="16px" style="margin-left: 20px" Width="215px" BackColor="#99CCFF"
DynamicHorizontalOffset="2" Font-Names="Verdana" Font-Size="Small"
ForeColor="#284E98" StaticSubMenuIndent="10px"
OnMenuItemClick="NavigationMenu0_MenuItemClick" >
<DynamicHoverStyle BackColor="#284E98" ForeColor="White" />
<DynamicMenuItemStyle HorizontalPadding="5px" VerticalPadding="2px" />
<DynamicMenuStyle BackColor="#B5C7DE" />
<DynamicSelectedStyle BackColor="#507CD1" />
<Items>
<asp:MenuItem Text="Edit Existing Item" ToolTip="Edit Item already in GP" Value="Edit Existing Item">
<asp:MenuItem Text="Change Item Status" ToolTip="Change the status of an item" Value="S" ></asp:MenuItem>
<asp:MenuItem Text="Edit Item Description" ToolTip="Edit the description of an Item" Value="D"></asp:MenuItem>
<asp:MenuItem Text="Change HTS Code" ToolTip="Change the HTS Code of an Item" Value="H"></asp:MenuItem>
</Items>
主页上的代码是:
protected void NavigationMenu0_MenuItemClick(Object sender, MenuEventArgs e)
//get the menu option selected by the user
{
var menu = (sender as Menu);
//ScriptManager.RegisterStartupScript(this, this.GetType(), "", "alert('Selected Menu is : " + menu + "')", true);
foreach (MenuItem item in menu.Items)
{
System.Diagnostics.Debug.Print(item.Text);
}
var clickedMenuItem = e.Item;
Session["1"] = e.Item.Text;
Response.Redirect("~/ChangeItem.aspx?=" + e.Item.Text);
}
据我了解,获得菜单值的最佳方法是 在我的ChangeItemPage上,我有以下内容:
protected void NavigationMenu0_MenuItemClick(Object sender, MenuEventArgs e)
//get the menu option selected by the user
{
string ChgItemType = Request.QueryString["value"];
WebMsgBox.Show("The Menu Item is: " + ChgItemType);
}
作为测试,我也有它: 受保护的void Page_Load(对象发送者,EventArgs e) { txtItemSearch.Focus();
//var menux = (sender as Menu).SelectedValue;
string ChgItemType = Request.QueryString["value"];
WebMsgBox.Show("The Menu Item is: " + ChgItemType);
}
ChangeItemType的值为NULL。
答案 0 :(得分:0)
我找到了答案。 更改Response.Redirect(“〜/ ChangeItem.aspx?=” + e.Item.Text);至 Response.Redirect(“〜/ ChangeItem.aspx?value =” + e.Item.Value);解决了。