Hello...
I 'm using RadControls for ASP.NET Q3 2007 and I have problems when exporting a grid to Excel. A strange gray square embracing some cells of the generated Excel is shown.
This is the Grid definition code:
And since the grid is controlled by RadAjaxManager, I placed the following code in HEAD section:
I have followed a document in this site that shows how to export to Excel in these scenarios, so I created a field named _exportExcel that is true when I press a export button placed in CommandItem of the grid. Therefore, these are the events I needed to implement:
ItemCreated event makes invisible filter row and command item row and other rows that I don't want the grid to export.
Any help will be greatly appreciated,
Thanks
Jaime
I 'm using RadControls for ASP.NET Q3 2007 and I have problems when exporting a grid to Excel. A strange gray square embracing some cells of the generated Excel is shown.
This is the Grid definition code:
| <rad:RadGrid ID="grdUsuariosSinConexion" runat="server" AllowFilteringByColumn="True" AllowPaging="True" |
| AllowSorting="True" AutoGenerateColumns="False" |
| GridLines="None" Skin="WebBlue" Width="95%" EnableAJAX="True" EnableAJAXLoadingTemplate="True" OnNeedDataSource="grdUsuariosSinConexion_NeedDataSource" OnItemDataBound="grdSinUso_ItemDataBound" OnItemCommand="grd_ItemCommand" OnItemCreated="grd_ItemCreated"> |
| <ExportSettings OpenInNewWindow="True" FileName="ExportUsuariosSinConexion" IgnorePaging="True"> |
| </ExportSettings> |
| <MasterTableView NoMasterRecordsText="No hay registros que mostrar." CommandItemDisplay="Top"> |
| <RowIndicatorColumn Visible="False"> |
| <HeaderStyle Width="20px" /> |
| </RowIndicatorColumn> |
| <ExpandCollapseColumn Resizable="False" Visible="False"> |
| <HeaderStyle Width="20px" /> |
| </ExpandCollapseColumn> |
| <Columns> |
| <rad:GridBoundColumn DataField="Nombre" HeaderText="Nombre" UniqueName="column"> |
| <ItemStyle Width="75%" /> |
| </rad:GridBoundColumn> |
| <rad:GridBoundColumn DataField="UltimaFecha" HeaderText="Ultima Fecha" UniqueName="colUltimaFecha" DataFormatString="{0:dd/MM/yyyy}" DataType="System.DateTime"> |
| <ItemStyle Width="25%" /> |
| </rad:GridBoundColumn> |
| </Columns> |
| <SortExpressions> |
| <rad:GridSortExpression FieldName="Nombre" /> |
| </SortExpressions> |
| <CommandItemTemplate> |
| <asp:ImageButton ID="btnExportUsoPorUsuario" runat="server" ImageUrl="~/Private/images/small_xls.gif" CommandName="ExportToExcel" ImageAlign="AbsMiddle" /> |
| </CommandItemTemplate> |
| </MasterTableView> |
| <HeaderStyle ForeColor="Gainsboro" HorizontalAlign="Center" /> |
| <PagerStyle HorizontalAlign="Left" Mode="NextPrevAndNumeric" NextPagesToolTip="Páginas Siguientes" |
| NextPageToolTip="Página Siguiente" PagerTextFormat="Cambiar página: {4} &nbsp;|&nbsp; Mostrando página {0} de {1}, usuarios {2} al {3} de {5}." |
| PrevPagesToolTip="Páginas Anteriores" PrevPageToolTip="Página Anterior" /> |
| <ItemStyle HorizontalAlign="Left" /> |
| <FilterItemStyle HorizontalAlign="Left" /> |
| <AlternatingItemStyle HorizontalAlign="Left" /> |
| <ClientSettings> |
| <ClientEvents OnRequestStart="mngRequestStarted" /> |
| </ClientSettings> |
| <CommandItemStyle HorizontalAlign="Right" /> |
| </rad:RadGrid> |
And since the grid is controlled by RadAjaxManager, I placed the following code in HEAD section:
| <script type="text/javascript"> |
| function mngRequestStarted(ajaxManager, eventArgs) |
| { |
| eventArgs.set_enableAjax(false); |
| } |
| </script> |
I have followed a document in this site that shows how to export to Excel in these scenarios, so I created a field named _exportExcel that is true when I press a export button placed in CommandItem of the grid. Therefore, these are the events I needed to implement:
| protected void grd_ItemCreated(object sender, GridItemEventArgs e) |
| { |
| e.Item.Visible = !_exportExcel || e.Item.ItemType == GridItemType.Header || e.Item.ItemType == GridItemType.AlternatingItem || e.Item.ItemType == GridItemType.Item; |
| } |
| protected void grd_ItemCommand(object source, GridCommandEventArgs e) |
| { |
| _exportExcel = e.CommandName == Telerik.WebControls.RadGrid.ExportToExcelCommandName; |
| } |
ItemCreated event makes invisible filter row and command item row and other rows that I don't want the grid to export.
Any help will be greatly appreciated,
Thanks
Jaime