Using the Below code you can auto generate the row number in the GridView, you just have to write a method taking the GridView as parameter.
public void AutoGenerateRowNumber(DataGridView gridView)
{
if (gridView != null)
{
for (int i = 0; (i <= (gridView.Rows.Count - 2)); i++)
{
dataGridView.Rows[i].HeaderCell.Value = string.Format((i + 1).ToString(), "0");
}
}
}