views:

370

answers:

0

Here is the code for the ASPX GridView:

<asp:GridView ID="gvCategories" runat="server" AutoGenerateColumns="false">

    <Columns>

    <asp:TemplateField HeaderText="Category Name">
    <ItemTemplate>
    <%# Eval("CategoryName") %>
    </ItemTemplate>
    </asp:TemplateField>

      <asp:TemplateField >
    <ItemTemplate>
    <div style="display:none">
    <textarea  rows="100" cols="20"></textarea>
    </div>
    </ItemTemplate>
    </asp:TemplateField>

    </Columns>


    </asp:GridView>

    <asp:Button ID="btnExport" runat="server" Text="Export" OnClick="ExportClick" />

and here is the export code:

 protected void ExportClick(object sender, EventArgs e)
        {
            string style = @"<style> .commentStyle { visibility:none; } </style> ";

            Response.ClearContent();
            Response.AddHeader("content-disposition", "attachment; filename=MyExcelFile.xls");

            Response.ContentType = "application/excel";

            StringWriter sw = new StringWriter();

            HtmlTextWriter htw = new HtmlTextWriter(sw);

            gvCategories.RenderControl(htw);

           // Response.Write(style);
            Response.Write(sw.ToString());

            Response.End();
        }

this export the grid fine but the textarea are also exported and they can be seen in the excel file. How can I stop this from happening? I cannot make TextArea a runat server. Don't ask it cannot be done in the application framework.