Export Error to Excel Gridview Column with Textbox
I have a Gridview
like this picture. Easyly in my last column, i keep a note for that row. (Simply, i made it edit, select, update that gridview classic properties.)
As you can see, my last column has a Textbox
(Multiline
)
Here is my last column gridview code;
<EditItemTemplate>
<asp:TextBox ID="txtTNOT" runat="server" Height="35" TextMode="MultiLine" DataSourceID="SqlDataSource8"></asp:TextBox>
<asp:SqlDataSource ID="SqlDataSource8" runat="server"
ConnectionString="<%$ ConnectionStrings:SqlServerCstr %>"
SelectCommand="SELECT [T_NOT] FROM [TAKIP] WHERE T_HESAP_NO = @T_HESAP_NO ">
<SelectParameters>
<asp:Parameter Name="T_HESAP_NO" Type="String" />
</SelectParameters>
</asp:SqlDataSource>
</EditItemTemplate>
And then i export this Gridview
to excel with this code;
protected void LinkButton1_Click(object sender, EventArgs e)
{
Response.Clear();
Response.AddHeader("content-disposition", "attachment;filename=TahTakip.xls");
Response.Charset = "";
Response.ContentType = "application/vnd.xls";
System.IO.StringWriter stringWrite = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
GridView1.Ren开发者_开发百科derControl(htmlWrite);
Response.Write(stringWrite.ToString());
Response.End();
}
There is no problem since this step. The problem is when i open this excel file, NOT
column is different the other columns. It has a Textbox
like this picture;
I don't want to be a Textbox
in my Excel
file. Just want a normal cell with a NOT value like left column.
How can i do that?
Best Regars,
Soner
you need to export datatable instead your GridView as you have controls in gridview that can't be export to excel
Edit: you can do like..
protected void btnExportExl_Click(object sender, EventArgs e)
{
StringWriter sw = new StringWriter();
HtmlTextWriter htw = new HtmlTextWriter(sw);
string attachment = "attachment; filename=BusinessUnit.xls";
Response.ClearContent();
Response.AddHeader("content-disposition", attachment);
GridView grd = new GridView();
grd.DataSource = datatable.DefaultView; // you get the datatable from DB that will not have controls!!!
grd.DataBind();
grd.RenderControl(htw);
Response.Write(sw.ToString());
Response.Flush();
Response.End();
}
please note, in the actual grid I have some image button and when I am exporting then I get the datatable again from DB
精彩评论