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

RADGRID Client-Side ClientEvents OnCommand and Server-side ItemCommand

4 Answers 925 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Robert Koerse
Top achievements
Rank 1
Robert Koerse asked on 08 Oct 2010, 03:12 PM
I've a radgrid with 3 custom GridButtonColumns

 

 

<telerik:GridButtonColumn UniqueName="SendColumn" ButtonType="LinkButton" CommandName="Select2"
Text="Versturen" ConfirmText="Verstuur order, weet u het zeker ?">
<HeaderStyle Width="60px" />
<ItemStyle Width="60px" HorizontalAlign="Center" />
</telerik:GridButtonColumn>
<telerik:GridButtonColumn UniqueName="CancelColumn" ButtonType="LinkButton" CommandName="Delete"
Text="Annuleren" ConfirmText="Annuleer order, weet u het zeker ?">
<HeaderStyle Width="60px" />
<ItemStyle Width="60px" HorizontalAlign="Center" />
</telerik:GridButtonColumn>
<telerik:GridButtonColumn UniqueName="ViewColumn" ButtonType="LinkButton" CommandName="Select1" Text="Inzien">
<HeaderStyle Width="50px" />
<ItemStyle Width="50px" HorizontalAlign="Center" />
</telerik:GridButtonColumn>
>>>>
  
<ClientEvents OnCommand="RadGridCommand" />
  
<<<<
  
    <script type="text/javascript"
        function RadGridCommand(sender, args) { 
            if (args.get_commandName() == "Select1") {
                var itemIndex = args.get_commandArgument();
                var rowID=sender.get_masterTableView().get_dataItems()[itemIndex].getDataKeyValue("opls_id");
                window.open("BestellingAcademieWBView.aspx?ID=" + rowID ,"contentpage"); 
                args.set_cancel(true);
            }
        }
</script>


I use Clientside event to open een nieuw page as you can see.

Serverside I have the follow code:

 

 

 

Private Sub RadGrid1_ItemCommand(ByVal source As Object, ByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles RadGrid1.ItemCommand
Try
    Select Case e.CommandName
    Case Is = "Select" 
        Dim editedItem As GridEditableItem = TryCast(e.Item, GridEditableItem)
        Dim intOrderID As Int32 = editedItem.GetDataKeyValue("opls_id")
        'Send1(item)
        'e.Item.OwnerTableView.Rebind()
    Case Is = "Select2"
        Dim editedItem As GridEditableItem = TryCast(e.Item, GridEditableItem)
        Dim intOrderID As Int32 = editedItem.GetDataKeyValue("opls_id")
        'Send1(item)
        'e.Item.OwnerTableView.Rebind()
    Case Is = "Delete"
        Dim editedItem As GridEditableItem = TryCast(e.Item, GridEditableItem)
        Dim intOrderID As Int32 = editedItem.GetDataKeyValue("opls_id")
        'SendOrderCancel(intOrderID)
        'e.Item.OwnerTableView.Rebind()
    End Select
Catch ex As Exception
   Me.AddErrorMessage(ex.Message)
End Try
End Sub

 

 

Facts:
- if i click column: CancelColumn (with commandname="Delete") is gives me the right intOrderID.
- if i click column: SendColumn (with commandname="Select2") is gives me the intOrderID of the FIRST row in the grid, even if i select e.g. the THIRD row.
- if i rename the CommandName="Select2" to "Select" and also handle serverside "Select" and i click column: SendColumn is gives me the right intOrderID (thus the row I selected).
- if I remove the <ClientEvents OnCommand="RadGridCommand" /> and i click column: SendColumn (with commandname="Select2") it gives me the right intOrderID (thus the row I selected).

Question:
I want to use the Cancelcolumn with CommandName="SELECT2" and also use the ClientEvent OnCommand.

Can anyone help me figure this out?!?!??!?

    




4 Answers, 1 is accepted

Sort by
0
Iana Tsolova
Telerik team
answered on 14 Oct 2010, 08:06 AM
Hi Robert,

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.

Check it out and let me know if this works for you.

Kind regards,
Iana
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
John Commandeur
Top achievements
Rank 1
answered on 14 Oct 2010, 08:36 AM
Thank you, it works.
0
Lola
Top achievements
Rank 1
answered on 16 Sep 2015, 07:52 AM
I tried to bind radgrid client side by json object.
I get empty rows so, i used onrowdatabound client event to draw data to grid.
but, i need to draw server controls (buttons) that needed to fire item command server side event???
Is it possible?
Thank you
0
Kostadin
Telerik team
answered on 21 Sep 2015, 07:34 AM
Hi Lola,

Note that grid server events won't fire if you are using client-side binding. So a possible solution is to use  OnCommand client event and/or RowDataBound which is fired for all rows such as ItemDataBound server event.

Regards,
Kostadin
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
Grid
Asked by
Robert Koerse
Top achievements
Rank 1
Answers by
Iana Tsolova
Telerik team
John Commandeur
Top achievements
Rank 1
Lola
Top achievements
Rank 1
Kostadin
Telerik team
Share this question
or