Add the following checks:
if (UpDatedataGridView2.Columns[e.ColumnIndex] is
DataGridViewButtonColumn &&
e.RowIndex != -1)
The first condition checks if a user clicked on the cell which belongs to a button column, while the second checks if the click happened in a row.
UPDATE: I forgot you have to check the ColumnIndex: if a user clicks on the header row, ColumnIndex has the value -1 and therefore UpDatedataGridView2.Columns[e.ColumnIndex] throws an exception. To summarize, the final checks should look like this:
if (e.ColumnIndex != -1 &&
e.RowIndex != -1 && UpDatedataGridView2.Columns[e.ColumnIndex] is
DataGridViewButtonColumn )