Context menu with panelbar get database value

6 posts, 1 answers
  1. David Blok
    David Blok avatar
    42 posts
    Member since:
    Nov 2009

    Posted 09 Dec 2009 Link to this post

    How can i get the database value ID

    aspx:
    <telerik:RadContextMenu ID="RadContextMenu1" runat="server" OnItemClick="RadMenu1_ItemClick">  
       <Items> 
           <telerik:RadMenuItem runat="server" Text="Pagina Toevoegen">  
           </telerik:RadMenuItem> 
           <telerik:RadMenuItem runat="server" Text="Pagina Wijzigen">  
           </telerik:RadMenuItem> 
           <telerik:RadMenuItem runat="server" Text="Pagina Verwijderen">  
           </telerik:RadMenuItem> 
       </Items> 
       <Targets> 
           <telerik:ContextMenuControlTarget ControlID="panelmenu1" /> 
       </Targets> 
    </telerik:RadContextMenu>   
     
     
    <telerik:RadAjaxPanel ID="RadAjaxPanel1" runat="server">  
     
    <telerik:RadPanelBar runat="server" ID="panelmenu1" Width="100%" PersistStateInCookie="True" OnPreRender="panelmenu1_PreRender" OnItemClick="RadPanelBar1_ItemClick" /> 
    <asp:label Runat="server" ID="Label1" Text="Standard"></asp:label> 
    </telerik:RadAjaxPanel> 

    vb:
        Protected Sub RadMenu1_ItemClick(ByVal sender As ObjectByVal e As RadMenuEventArgs)  
     
            Select Case e.Item.Text  
                Case "Pagina Toevoegen" 
     
                    ' NEED ID FROM SELECTED ITEM HERE  
     
                    Exit Select 
            End Select 
        End Sub 
     

    The idea is to get the right database ID and send that ID to the radwindow.

    So i anyone has a code for it, it would be very helpfull
  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 10 Dec 2009 Link to this post

    Hi David,

    I am not quite sure about your scenario. I suppose you want to pass the PanelBarItem Text to RadWindow on clicking the RadContextMenu.

    aspx:
     
    <telerik:RadPanelBar ID="RadPanelBar1" runat="server" DataSourceID="SqlDataSource1" DataTextField="TextField" DataValueField="ValueField" OnItemClick="RadPanelBar1_ItemClick"
        
    </telerik:RadPanelBar> 

    javascript:
     
    <script type="text/javascript"
        function OnClientItemClicked(sender, args) { 
            if (args.get_item().get_text() == "Pagina Toevoegen") { 
                var url = "Default.aspx?id=" + args.get_targetElement().innerHTML
                radopen(url, ""); 
                sender.hide(); 
            } 
        } 
    </script> 

    -Shinu.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. David Blok
    David Blok avatar
    42 posts
    Member since:
    Nov 2009

    Posted 10 Dec 2009 Link to this post

    Well the panelbar is populated with data from sql

        Private Sub BindToDataSet()  
     
            Dim adapter As New SqlDataAdapter("SELECT * FROM TblPages where MenuID = " + MenuIDvalue, _  
                ConfigurationManager.ConnectionStrings("Varodb").ConnectionString)  
     
            Dim Menu As New DataSet()  
     
            adapter.Fill(Menu)  
     
            panelmenu1.DataTextField = "Pagename" 
            panelmenu1.DataFieldID = "ID" 
            panelmenu1.DataFieldParentID = "PageID" 
     
            panelmenu1.DataSource = Menu  
            panelmenu1.DataBind()  
     
     
     
        End Sub 

    On a panel leftclick i get the database ID value an it works :
        Protected Sub RadPanelBar1_ItemClick(ByVal sender As ObjectByVal e As Telerik.Web.UI.RadPanelBarEventArgs)  
     
            Threading.Thread.Sleep(200)  
            Label1.Text = "Clicked panel item - " + e.Item.Attributes("PageID")  
     
            Response.Redirect("/?Node=" + e.Item.Attributes("PageID"))  
     
        End Sub 

    But i need it  on the context menu like here :
        Protected Sub RadMenu1_ItemClick(ByVal sender As ObjectByVal e As RadMenuEventArgs)  
     
            Select Case e.Item.Text  
                Case "Pagina Toevoegen" 
     
                    ' NEED ID FROM SELECTED ITEM HERE  
     
                    Exit Select 
            End Select 
        End Sub 

    So if they choose the option on the context menu i should get the database ID and open a rad windows with the database ID send true an URL string (all server sided)

  5. David Blok
    David Blok avatar
    42 posts
    Member since:
    Nov 2009

    Posted 14 Dec 2009 Link to this post

    Hi

    I'm trying to get it working client sided now with the example script from above.

    But what is the code to get a database attribute like ID ?
    args.get_targetElement().innerHTML

    This get the Name of the Page
  6. Answer
    Yana
    Admin
    Yana avatar
    4554 posts

    Posted 14 Dec 2009 Link to this post

    Hello David,

    You can access the panelbar item for which the context menu is opened only client-side, please subscribe to OnClientShowing event of the context menu and in its handler:

    function menuShowing(sender, args) {
        var target = args.get_targetElement();
        if (target.className != "rpText") {
            args.set_cancel(true);
        }
        else {
            var panelBarItem = $find("<%=panelmenu1.ClientID %>").findItemByText(target.innerHTML);
            sender.trackChanges();
            sender.get_items().getItem(0).get_attributes().setAttribute("pItem", panelBarItem.get_attributes().getAttribute("PageID"));
            sender.commitChanges();
        }
    }

    and then in ItemClick event you can get this attribute like this:

    protected void RadMenu1_ItemClick(object sender, Telerik.Web.UI.RadMenuEventArgs e)
    {
        string panelBarValue = RadContextMenu1.Items[0].Attributes["pItem"].ToString();
    }

    I hope this helps.


    Best wishes,
    Yana
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  7. David Blok
    David Blok avatar
    42 posts
    Member since:
    Nov 2009

    Posted 14 Dec 2009 Link to this post

    It works perfectly now, many thanks
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017