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

Calling ItemCommand from external button

5 Answers 107 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Garrett
Top achievements
Rank 1
Garrett asked on 15 May 2014, 06:15 PM
Hi! 

I have a grid that has an update command inside of RadGrid1_ItemCommand(object sender, GridCommandEventArgs e)


I want to run that update command when a radbutton is clicked further down in the page.

What do I pass as "e" to make the update work with the button click?

5 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 1
answered on 16 May 2014, 06:25 AM
Hi Garrett,

If you want to invoke a command in the OnItemCommand event for a button outside Grid, you can use the fireCommand. Check the following code snippet:

ASPX:
<telerik:RadGrid ID="RadGrid1" runat="server">  
</telerik:RadGrid>
<telerik:RadButton ID="rbtnUpdate" runat="server" Text="Update" OnClientClicked="OnClientClicked">
</telerik:RadButton>

JS:
<script type="text/javascript">
  function OnClientClicked() {     
      var grid = $find("<%=RadGrid1.ClientID %>");
      var master = grid.get_masterTableView();
      master.fireCommand("YourCommandName", "");
  }
</script>

C#:
protected void RadGrid1_ItemCommand(object sender, GridCommandEventArgs e)
{
  if (e.CommandName == "YourCommandName")
  {
    //Your code
  }
}

Thanks,
Princy
0
Garrett
Top achievements
Rank 1
answered on 16 May 2014, 02:05 PM
Wonderful! I will implement this later today and report back. Thank you.
0
Garrett
Top achievements
Rank 1
answered on 16 May 2014, 02:36 PM
I'm getting this as an error:

Specified argument was out of the range of valid values. Parameter name: ItemHierarchicalIndex

This grid is in a radwindow if this is matters.
0
Garrett
Top achievements
Rank 1
answered on 16 May 2014, 03:08 PM
I changed master.fireCommand("YourCommandName", ""); to master.fireCommand("YourCommandName", "0"); and it seems to be working. Thank you!
0
RJ
Top achievements
Rank 1
answered on 19 Aug 2014, 10:09 AM
Any conversion of this code to Classic RadControls. Thanks

var grid = $find("<%=RadGrid1.ClientID %>"); 
var master = grid.get_masterTableView();
master.fireCommand("YourCommandName", "");
Tags
Grid
Asked by
Garrett
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 1
Garrett
Top achievements
Rank 1
RJ
Top achievements
Rank 1
Share this question
or