Okay what you are referring to is called as export to excel functionality.
What you have to do is you have to simply bind the data to your gridview and display it then you can create a button on which you will write the functionality for export to excel.
For e.g
<asp:Button ID="btnExportToExcel" runat="server" Text="Export to Excel from Gridview" OnClick="btnExportToExcel_Click"
/>
And your function would be something like this thats all you have to do nothing more than that:
protected void btnExportToExcel_Click(object sender, EventArgs e)
{
string attachment = "attachment; filename=Emp.xls";
Response.ClearContent();
Response.AddHeader("content-disposition", attachment);
Response.ContentType = "application/ms-excel";
StringWriter sw = new StringWriter();
HtmlTextWriter htw = new HtmlTextWriter(sw);
GridViewExport.RenderControl(htw);
Response.Write(sw.ToString());
Response.End();
}