Get your searched datatable and use it for exporting
protected void Bexcel_Click(object sender, EventArgs e)
{
DataTable table = GetSearchedData();
ExportGridToExcel(table);
}
private void ExportGridToExcel(DataTable table)
{
Response.Clear();
Response.ClearContent();
Response.ClearHeaders();
string FileName = "Example" + DateTime.Now + ".xls";
StringWriter writter = new StringWriter();
HtmlTextWriter html = new HtmlTextWriter(writter);
Response.ContentType = "application/vnd.ms-excel";
Response.AddHeader("Content-Disposition", "attachment,filename" + FileName);
GridView1.HeaderStyle.Font.Bold = true;
GridView1.AllowPaging = false;
GridView1.DataSource = table;
GridView1.DataBind();
GridView1.RenderControl(html);
Response.Write(writter.ToString());
Response.End();
}