You dont want to write it in Page_load. You Can use
RowCommand event of Gridview.
For Example Cancel Button in ASPX inside Grid
<asp:imagebutton id="CancelButton" runat="server" imageurl="~/images/CancelButton.jpg" commandname="Cancel" xmlns:asp="#unknown" />
C# Code
protected void MainGridView_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "Cancel")
{
if (System.Windows.Forms.MessageBox.Show("Sure want to Cancel Appointment?", "Cancel Appointment",
System.Windows.Forms.MessageBoxButtons.YesNo, System.Windows.Forms.MessageBoxIcon.Question) == DialogResult.Yes)
{
systemBusinessLayer = new BusinessLayer();
systemBusinessLayer.cancelAppointmentByEmployee(Convert.ToInt32(SlotId), Convert.ToInt32(EmpRecNr));
}
}
}