User2028823583 posted
Hi. I have a vb.net gridview that gets data from a sql datasource and has a template field. In that template field, there is a textbox in an ItemTemplate. That all works great, the problem I'm having is when the user
Exports to Excel. The gridview looks fine with all the columns, EXCEPT for the column that has that ItemTemplate with the TextBox. When it exports to excel, it actually displays a textbox inside the cell of the Excel spreadsheet.
Is it possible on the click of the button to Export To Excel, to take the value entered in the textbox by the user, and display it in the ExcelSpreadsheet as a regular field like the rest of the databound columns?
Here's my TemplateField from my gridview...
<asp:TemplateField HeaderText="Salary" SortExpression="Salary">
<ItemTemplate>
<asp:TextBox ID="txtSalary" runat="server" Text='<%# Bind("Salary")%>'></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
and here is my export to Excel
Private Sub ExportToExcel(ByVal strFileName As String, ByVal dg As GridView)
Response.Clear()
Response.Buffer = True
Response.ContentType = "application/vnd.ms-excel"
Response.AddHeader("content-disposition", "attachment;filename=" & strFileName)
Response.Charset = ""
Me.EnableViewState = False
Dim StringWriter As New System.IO.StringWriter()
Dim HtmlTextWriter As New System.Web.UI.HtmlTextWriter(StringWriter)
gvReport.RenderControl(HtmlTextWriter)
Response.Write(StringWriter.ToString())
Response.End()
End Sub