Use
DataGrid1.DataSource as DataTable
If you have defined a DataSet/Datatable as a datasource to your Gridview/Datagrid then you don't need to loop through.
Here:
DataTable dt = new DataTable();
dt.Columns.Add("ID");
dt.Columns.Add("IDValue");
dt.Rows.Add("1", "One");
dt.Rows.Add("12", "One2");
dt.Rows.Add("13", "One3");
dt.Rows.Add("14", "One4");
dt.Rows.Add("15", "One5");
DataGrid1.DataSource = dt;
DataGrid1.DataBind();
protected void Button1_Click(object sender, EventArgs e)
{
DataTable dt;
dt = DataGrid1.DataSource as DataTable;
}