HTML
<asp:GridView ID="GridView1" HeaderStyle-BackColor="#3AC0F2" HeaderStyle-ForeColor="White"
runat="server" AutoGenerateColumns="false">
<Columns>
<asp:BoundField DataField="Id" HeaderText="Id" ItemStyle-Width="30" />
<asp:BoundField DataField="Name" HeaderText="Name" ItemStyle-Width="150" />
<asp:BoundField DataField="Country" HeaderText="Country" ItemStyle-Width="150" />
</Columns>
</asp:GridView>
<asp:Button runat="server" ID="btnExportGridview" OnClick="ExportGridview" Text="Gridview to Datatable" />
CODE
protected void ExportGridview(object sender, EventArgs e)
{
DataSet ds = new DataSet();
ds.Tables.Add();
ds.Tables[0].Columns.AddRange(new DataColumn[3] { new DataColumn("Id", typeof(int)),
new DataColumn("Name", typeof(string)),
new DataColumn("Country",typeof(string)) });
foreach (GridViewRow row in GridView1.Rows)
{
ds.Tables[0].Rows.Add(row.Cells[0].Text, row.Cells[1].Text);
}
}