Saludos, estoy tratando de exportar el siguiente gridview a excel:
<asp:GridView ID="gv1" runat="server" AutoGenerateColumns="false" AllowPaging="true" PageSize="10" ShowFooter="true" PagerSettings-Visible="false" SkinID="GridNormal">
<Columns>
<asp:TemplateField HeaderText="Segmento">
<ItemTemplate><div align="left">
<a href="VtasSegSupervisores.aspx?period=<%# Server.HtmlDecode(Eval("periodo").ToString()) %>&segId=<%# Server.HtmlDecode(Eval("Segmento").ToString()) %>&FiltroEmp=<%#CType(wucFiltros.FindControl("ddlE mpresa"), DropDownList).SelectedValue%>">
<%#Server.HtmlDecode(Eval("Segmento").ToString() & "==>" & Eval("Clientes"))%>
</a></div>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="MontoTrim" HeaderText="Promedio" HtmlEncode="false" DataFormatString="{0:C2}" />
<asp:BoundField DataField="MontoPresu" HeaderText="Presupuesto" HtmlEncode="false" DataFormatString="{0:C2}" />
<asp:BoundField DataField="VtaNeta" HeaderText="Netas" HtmlEncode="false" DataFormatString="{0:C2}" />
<asp:BoundField DataField="MontoBruto" HeaderText="Brutas" HtmlEncode="false" DataFormatString="{0:C2}" />
<asp:BoundField DataField="ProyVtaNeta" HeaderText="Vta. Neta" HtmlEncode="false" DataFormatString="{0:C2}" />
<asp:TemplateField HeaderText="Venta(a la fecha)">
<ItemTemplate>
<asp:Label ID="lblPorcCump" runat="server" Text='<%# Format(CDec(Eval("PorCump")), "####0.00") & "%" %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Pres.">
<ItemTemplate>
<asp:Label ID="lblPorcProyPres" runat="server" Text='<%# Format(CDec(Eval("PorcProyPres")), "####0.00") & "%" %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Venta$">
<ItemTemplate>
<asp:Label ID="lblPorcUtil" runat="server" Text='<%# Format(CDec(Eval("PorcUtil")), "####0.00") & "%" %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="DevCInc" HeaderText="Con Inc." HtmlEncode="false" DataFormatString="{0:C2}" />
<asp:BoundField DataField="DevSInc" HeaderText="Sin Inc." HtmlEncode="false" DataFormatString="{0:C2}" />
<asp:TemplateField HeaderText="Part.">
<ItemTemplate>
<asp:Label ID="lblProcPart" runat="server" Text='<%# Format(CDec(Eval("PorcPartip")), "####0.00") & "%" %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="PorcDevol" HeaderText="Dev." HtmlEncode="false" DataFormatString="{0:####0.00%}" />
<asp:BoundField DataField="Utilidad" HeaderText="" Visible="false" />
</Columns>
</asp:GridView>
el gridview se exporta pero por ejemplo si la consulta trae 5 filas las primeras 4 filas se exportan correctamente y la ultima no salen ninguno de los valores que son templatefield, pero solo de la ultima fila, si solo trae una fila la consulta es lo mismo solo presenta las celdas que no son templatefield.
Si alguien tiene alguna idea de porque me pasa esto se lo agradeceria mucho.
Este es mi codigo de exportacion:
Public Shared Sub Export(ByVal fileName As String, ByVal gv As GridView)
HttpContext.Current.Response.Clear()
HttpContext.Current.Response.AddHeader("content-disposition", String.Format("attachment; filename={0}", fileName))
HttpContext.Current.Response.ContentType = "application/ms-excel"
Dim sw As StringWriter = New StringWriter
Dim htw As HtmlTextWriter = New HtmlTextWriter(sw)
' Create a form to contain the grid
Dim table As Table = New Table
table.GridLines = gv.GridLines
' add the header row to the table
If (Not (gv.HeaderRow) Is Nothing) Then
ExportGridViewExcel.PrepareControl*****port(gv.Hea derRow)
table.Rows.Add(gv.HeaderRow)
End If
' add each of the data rows to the table
For Each row As GridViewRow In gv.Rows
ExportGridViewExcel.PrepareControl*****port(row)
table.Rows.Add(row)
Next
' add the footer row to the table
If (Not (gv.FooterRow) Is Nothing) Then
ExportGridViewExcel.PrepareControl*****port(gv.Foo terRow)
table.Rows.Add(gv.FooterRow)
End If
' render the table into the htmlwriter
table.RenderControl(htw)
' render the htmlwriter into the response
HttpContext.Current.Response.Write(sw.ToString)
HttpContext.Current.Response.End()
End Sub