i read many articles on `stackoverflow` and `code project` about this and i also implement this to my code and my page. But i can not export gridview data to excel. I am binding my `gridview` with `object datasource` on the page. But have not success to export to excel. Can you please tell me what i am doing mistake. All the flow of code i am giving below .

```
<%@ Page Language="C#" Theme="Default" MasterPageFile="~/Order/Order.master" AutoEventWireup="true" CodeFile="ActiveOrders.aspx.cs" Inherits="ActiveOrders" Title="SimplyDispatch-ActiveOrders List" EnableEventValidation="false" %>  

<data:EntityGridView ID="GridView1" runat="server" AutoGenerateColumns="False" OnSelectedIndexChanged="GridView1_SelectedIndexChanged"
 DataSourceID="ActiveOrdersDataSource" Width="100%" DataKeyNames="OrderNo" AllowMultiColumnSorting="false"                                         DefaultSortColumnName="OrderNo" OnRowCommand="GridView1_RowCommond" OnRowDataBound="GridView1_OnRowDataBound"                                          AllowSorting="true" DefaultSortDirection="Descending"                                         PageSize="50"  EnableViewState="true" >
    <Columns>
     <asp:BoundField DataField="OrderNo" HeaderStyle-HorizontalAlign="Right" ItemStyle-HorizontalAlign="Right"                                            HeaderText="Order No" SortExpression="[OrderNo]" />
      <asp:BoundField DataField="OrderDate" HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Center"                                               DataFormatString="{0:d}" HtmlEncode="False" HeaderText="Order Date" SortExpression="[OrderDate]" />
    </Columns>                 

     <EmptyDataTemplate>

   </EmptyDataTemplate>

    </data:EntityGridView>

```

Grid view datasource 

```
 <data:ActiveOrdersDataSource ID="ActiveOrdersDataSource" runat="server" SelectMethod="GetPaged" EnablePaging="True" EnableSorting="True" EnableDeepLoad="True">
</data:ActiveOrdersDataSource>

```

my code to export to excel is below

```
 protected void ExportToExcel(object sender, EventArgs e)
    {
        try
        {
 Response.Clear();
            Response.ClearHeaders();
            Response.Buffer = true;
            Response.AddHeader("content-disposition", "attachment;filename=" + "Excelsheet_" + DateTime.Now.Ticks.ToString() + ".xls");
            Response.Charset = "";
            Response.ContentType = "application/vnd.xls";
            StringWriter StringWriter = new System.IO.StringWriter();
            HtmlTextWriter HtmlTextWriter = new HtmlTextWriter(StringWriter);
            GridView1.AllowSorting = false;
            GridView1.RenderControl(HtmlTextWriter);// render gridview control
            Response.Write(StringWriter.ToString());
            Response.End();
        }
        catch (Exception ex)
        {

        }
    }

public override void VerifyRenderingInServerForm(Control control)
    {
        /* Confirms that an HtmlForm control is rendered for the specified ASP.NET
           server control at run time. */
    }

```