ASPXNAVBAR获取选定的导航栏项名称

时间:2017-02-24 07:48:37

标签: javascript asp.net vb.net devexpress

我这里有一个ASPxNavbar我想在每次点击导航栏项目并在标签上显示时获取NavBar项目名称。我尝试用JavaScript做这件事,但似乎没什么用。

这是我到目前为止所尝试的内容

<dx:ASPxLabel ID="ASPxLabel1" runat="server" Text="ASPxLabel">
        </dx:ASPxLabel>

<dx:ASPxNavBar ID="ASPxNavBar1" runat="server" EnableAnimation="True" Width="100%" 
        Theme="Material" AllowSelectItem="true" Target="contentUrlPane" ClientInstanceName="NavbarClick">
    <LinkStyle>
        <HoverFont Underline="False" />
    </LinkStyle>    
    <Border BorderWidth="0px" />
    <Paddings Padding="0px" />
    <GroupHeaderStyle HorizontalAlign="left" />

    <ItemStyle HorizontalAlign="left">
    <SelectedStyle BackColor="#404652 " ForeColor="#a2a2a2" />
    </ItemStyle>

<ClientSideEvents ItemClick="function NavbarClick(s, e) {
 ave  = e.item.name;
alert(ave)
document.getElementById('ASPxLabel1').innerHTML = ave;
}"/>
    <Groups>
    <dx:NavBarGroup Text="DASHBOARD" ></dx:NavBarGroup>
    <dx:NavBarGroup Text="Forms">
        <Items>
        <dx:NavBarItem Text="Cancel Memo" NavigateUrl="sample.aspx" Selected="True" Name = "Sample Title Here">
            <Image Height="18px" Url="Content/Images/1.png" Width="18px"  />
        </dx:NavBarItem>
        <dx:NavBarItem Text="Change Memo" NavigateUrl="Sample2.aspx" Name = "Another sample title here">
            <Image Height="18px" Url="Content/Images/2.png" Width="18px" />
        </dx:NavBarItem>
        </Items>
    </dx:NavBarGroup>
   </Groups>
   </dx:ASPxNavBar>

非常感谢任何帮助。谢谢!

3 个答案:

答案 0 :(得分:0)

您所拥有的内容似乎是正确的,但是请注意,您已将NavBar的ClientInstanceName称为NavBarClick

...
 Theme="Material" AllowSelectItem="true" Target="contentUrlPane"
 ClientInstanceName="NavbarClick">
...

您的ItemClick JS处理程序,您也调用了NavbarClick

...
<ClientSideEvents ItemClick="function NavbarClick(s, e) {
...

我不确定它会起作用。尝试重命名您的ItemClick处理程序,例如:

<ClientSideEvents ItemClick="function OnNavbarClick(s, e) {

HTH

答案 1 :(得分:0)

按如下所示纠正客户端ItemClick功能分配:

<ClientSideEvents ItemClick="function(s, e) {
    ave  = e.item.name;
    alert(ave);
}"/>

答案 2 :(得分:-1)

protected void FiltersNavBar_ItemClick(object source, NavBarItemEventArgs e)
{
   var strValue = e.Item.Name;
   if (strValue == "New")
   {
   }
}