This is a migrated thread and some comments may be shown as answers.

Split Button in RadGrid - How to get selected row clientside

4 Answers 154 Views
Button
This is a migrated thread and some comments may be shown as answers.
john81
Top achievements
Rank 1
john81 asked on 14 Sep 2012, 04:06 PM
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);
}

4 Answers, 1 is accepted

Sort by
0
Slav
Telerik team
answered on 19 Sep 2012, 08:46 AM
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.
0
john81
Top achievements
Rank 1
answered on 19 Sep 2012, 01:19 PM
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.
0
Slav
Telerik team
answered on 21 Sep 2012, 01:40 PM
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.
0
john81
Top achievements
Rank 1
answered on 21 Sep 2012, 01:56 PM
That fixed it.  Thanks!
Tags
Button
Asked by
john81
Top achievements
Rank 1
Answers by
Slav
Telerik team
john81
Top achievements
Rank 1
Share this question
or