This is a simple example of a grid's toolbar customization. For this purpose you have to override the list\grid_toolbar.tpl template and then bind it with the OnGetCustomTemplate event.
In the example below a grid toolbar is equipped with a new button allowing to select a random record. Click the button to see the event handler code.
A more complex example of customizing grid toolbar can be found on this page.