c# get gridview DataKeyNames

C#
foreach (GridViewRow row in grid.Rows)
{
    int id = Convert.ToInt32(grid.DataKeys[row.RowIndex].Value.ToString());
}
Source

Also in C#: