Export page content to excel
<p>I have .aspx page with labels, text boxes and radio buttons. I am binding data to them dynamically. Now i have kept excel button at the bottom of the page to export complete page contents to the excel. </p>

<p>When i am trying to export complete dynamic generated data which as text and checked radio buttons to excel then it is giving me error message as "Missing CSS stylesheet".</p>

<p>Can you please help how to export page content data to excel with preserving CSS Styles which are present?</p>

<p>"""PLEASE NOTE THEIR IS NO GRIDVIEW IN MY PAGE......"""" I have posted in other sites but they are giving information related to GRIDVIEW.</p>

<p>Please find the code i have used:</p>

<pre><code>protected void BtnExpExcel_Click(object sender, EventArgs e)
{
    HttpContext.Current.Response.ContentType = "application/vnd.xls";
    HttpContext.Current.Response.AddHeader("content-disposition", "attachment;filename=1.xls");
    System.IO.StringWriter stringWrite = new System.IO.StringWriter();
    System.Web.UI.HtmlTextWriter htmlWrite = new System.Web.UI.HtmlTextWriter(stringWrite);
    System.Web.UI.Page sPage = new System.Web.UI.Page();
   //Binding page contents to render control
    sPage.RenderControl(htmlWrite);
    HttpContext.Current.Response.Write(stringWrite.ToString());
    HttpContext.Current.Response.Flush();
}

&lt;table class="tblStyle" width="100%"&gt;
        &lt;tr&gt;
            &lt;td style="height: 21px"&gt;
                &lt;asp:Literal ID="LiQues" runat="server"&gt;&lt;/asp:Literal&gt;
                &lt;asp:PlaceHolder ID="phQues" runat="server" &gt;&lt;/asp:PlaceHolder&gt;
            &lt;/td&gt;
        &lt;/tr&gt;
&lt;/table&gt;


public void AddCntrls()
{
 phQues.Controls.Add(new LiteralControl("&lt;table id='tblSurveyQues' runat='server'&gt;"));

        phQues.Controls.Add(new LiteralControl(@" &lt;tr&gt;
                                &lt;td colspan='2'&gt;
                                &lt;/td&gt;
                                &lt;td colspan='11' class='center'&gt;
People soft engineering                                &lt;/td&gt;
                                &lt;td class='gray'&gt;
                                    &amp;nbsp;
                                &lt;/td&gt;

                            &lt;/tr&gt;"));



        for (int i = 0; i &lt; dtsat.Rows.Count; i++)
        {

            strQSection = dtQuestion.Rows[i]["QSection"].ToString();
            strQuestion = dtQuestion.Rows[i]["Question"].ToString();
            QSID = dtQuestion.Rows[i]["QOrder"].ToString();
            QID = dtQuestion.Rows[i]["QID"].ToString();
            if (strQSection != strPreQSection)
            {

                /// &lt;param name="dtQuestion"&gt;&lt;/param&gt;

                phQues.Controls.Add(new LiteralControl(@"&lt;tr&gt;
                                    &lt;td colspan='2' class='section'&gt;"
                                   + strQSection +
                                   @"&lt;/td&gt;                                    
                                &lt;td class='section' align='center'&gt;
                                    rating 
                                &lt;/td&gt;
                                &lt;/tr&gt;"));
    }
}
</code></pre>
