How To exporting to Excel parent and nested GridView data?
<p>I have a gridview and some nested gridview inside it, when I try to export gridview data to Excel I get downloaded entire web page, I am sure it is beacause of nested gridviews.</p>

<p>How can I export parent and nested gridview data into an Excel sheet?</p>

<p>I use the following code to export to excel</p>

<pre><code>            gvExportToExcel.DataSource = objDs;
            gvExportToExcel.DataBind();           
            System.Web.HttpContext curContext = System.Web.HttpContext.Current;
            System.IO.StringWriter strWriter = null;
            System.Web.UI.HtmlTextWriter htmlWriter = null;                       
            curContext.Response.Clear();
            curContext.Response.Buffer = true;
            curContext.Response.AddHeader("content-disposition", "attachment; filename=" + System.Web.HttpUtility.UrlEncode("SearchSubmissionResult", System.Text.Encoding.UTF8) + ".xls");
            curContext.Response.ContentType = "application/vnd.ms-excel";
            curContext.Response.Write("&lt;meta http-equiv=Content-Type content=text/html;charset=UTF-8&gt;");
            strWriter = new System.IO.StringWriter();
            htmlWriter = new System.Web.UI.HtmlTextWriter(strWriter);
            this.ClearControls(gvExportToExcel);
            gvExportToExcel.RenderControl(htmlWriter);
            curContext.Response.Write(strWriter.ToString());
            curContext.Response.End();                 
</code></pre>
