Split Button in RadGrid - How to get selected row clientside

5 posts, 0 answers
  1. john81
    john81 avatar
    36 posts
    Member since:
    Jan 2010

    Posted 14 Sep 2012 Link to this post

    I have a split button in a grid.  When I click the split button the context menu shows.  When I click on the context menu the OnItemClick fires and I can get the context item selection.  But what I can't figure out how to do is get the datakey value for the radgrid row where I click the button.  If I select the row first I can get the datakey value via RowSelected or RowSelecting.  But niether of those events fire when I click on the split button because its OnClientClicked fires.  I'd like to get that value without having to select the row first.

    <telerik:RadContextMenu ID="radCtxMenuActions" runat="server" CausesValidation="true" OnItemClick="radCtxMenuActions_ItemClick">
        <Items>
            <telerik:RadMenuItem Text="Option 1" />
            <telerik:RadMenuItem Text="Option 2" />
            <telerik:RadMenuItem Text="Option 3" />
        </Items>
    </telerik:RadContextMenu>

    protected void radCtxMenuActions_ItemClick(object sender, RadMenuEventArgs e)
    {
     
        int id = Convert.ToInt32(Request.Form["radGridClickedRowValue"]);
     
        switch (e.Item.Text)
        {
               case "Option 1":
               // do action with id
                break;
        }
     
    }


    if (args.IsSplitButtonClick() || !sender.get_commandName())
    {
         // get selected row here and save to hidden field so I can use it in RadContextMenu OnItemClick
         var id = ?????
         document.getElementById("radGridClickedRowValue").value = id;

        var currentLocation = $telerik.getLocation(sender.get_element());
        var contextMenu = $find("<%=radCtxMenuActions.ClientID%>");
        contextMenu.showAt(currentLocation.x, currentLocation.y + 22);
    }
  2. Slav
    Admin
    Slav avatar
    1356 posts

    Posted 19 Sep 2012 Link to this post

    Hi John,

    You can use the OnClientClicked event of RadButton in order to programmatically select the RadGrid row in which the clicked button resides. You can find attached a sample page that demonstrates this approach. Please use it as a reference for incorporating the desired functionality in your actual project.


    Kind regards,
    Slav
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. john81
    john81 avatar
    36 posts
    Member since:
    Jan 2010

    Posted 19 Sep 2012 Link to this post

    The code you provided does select the row correctly but it breaks the context menu display.  The context menu opens then closes on click.  It needs to stay open until it gets a mouse click so the user can make a selection.
  5. Slav
    Admin
    Slav avatar
    1356 posts

    Posted 21 Sep 2012 Link to this post

    Hello John,

    Indeed, it appears that there is an error in my script that causes the context menu to close when you try to open it in an already selected row of the RadGrid. To fix this, please replace the following lines
    while (node && node.className != "rgRow" && node.className != "rgAltRow") {
        node = node.parentNode;
    }
    with
    while (node && node.className.indexOf("rgRow") == -1 && node.className.indexOf("rgAltRow") == -1) {
        node = node.parentNode;
    }
     

    Greetings,
    Slav
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
  6. john81
    john81 avatar
    36 posts
    Member since:
    Jan 2010

    Posted 21 Sep 2012 Link to this post

    That fixed it.  Thanks!
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017