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

problem with RadGrid if using ClientEvents-OnCommand and ItemCommand

1 Answer 144 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Romek Olearski
Top achievements
Rank 1
Romek Olearski asked on 02 Feb 2011, 11:53 AM
Hi,
i am facing following problem with RadGrid if i am using ClientEvents-OnCommand.
the problem is if i am adding ClientEvents-OnCommand in radgrid, it does fire itemcomamnd event of grid for user defined command,
but it always points to the first item in radgrid (e.Item) .


 .ascx

       <telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">

            <script type="text/javascript">

                    function OnCommand(sender, args) {
                    // it is doing nothing
                }

            </script>

        </telerik:RadCodeBlock>



.cs

    protected void Page_Load(object sender, EventArgs e)
    {
        this.RadGrid1.ItemCommand += OnItemCommand;
        this.RadGrid1.ClientSettings.ClientEvents.OnCommand = "OnCommand";
    }

    void OnItemCommand(object source, Telerik.Web.UI.GridCommandEventArgs e)
    {
        if (e.Item == null)
            return;

        switch (e.CommandName)
        {
            // user defined
            case "Standard":

                 GridDataItem item = (GridDataItem)e.Item;

                // e.g  id is always Id of the first item in radgrid if ClientEvents-OnCommand is defined
                var id = new Guid(item["Id"].Text);
... etc


if i remove ClientEvents-OnCommand, it works fine.


am i doing anything wrong ?

1 Answer, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 03 Feb 2011, 11:11 AM
Hello Romek,

When custom command is fired, and the OnCommand client-side event is handled, the ItemCommand is fired from the first grid item. However you can get the key values from the e.CommandArgument parameter.

Thanks,
Princy.
Tags
Grid
Asked by
Romek Olearski
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Share this question
or