need create radgrid to dynamic way and also to export to Excel, but when exporting to excel only creates a blank file.
this is how I load dynamically the columns I get from a local variable is an array of string.
do not know if this will be the right approach?
<telerik:RadGrid ID="rgCajas" runat="server" DataSourceID="odsCajas" OnSortCommand="rgCajas_SortCommand" OnPageIndexChanged="rgCajas_PageIndexChanged" OnPageSizeChanged="rgCajas_PageSizeChanged" AllowSorting="True" PageSize="15" AllowPaging="True" AllowMultiRowSelection="True" Gridlines="None" MasterTableView-NoMasterRecordsText="No se encontrĂ³ registro" Width="40%" DataSourcePersistenceMode="ViewState"> <PagerStyle Mode="NextPrevAndNumeric" PagerTextFormat="{4} Registros {2}-{3} de {5}" PageSizeLabelText="# Registros"></PagerStyle> <ExportSettings ExportOnlyData="true" IgnorePaging="true" OpenInNewWindow="true"> <Excel Format="ExcelML" /> </ExportSettings> <MasterTableView DataSourceID="odsCajas" CommandItemDisplay="Top" AutoGenerateColumns="false" UseAllDataFields="true"> <CommandItemSettings ShowExportToExcelButton="true" ShowAddNewRecordButton="false" ShowRefreshButton="False" /> <Columns> </Columns> </MasterTableView> </telerik:RadGrid> <asp:ObjectDataSource runat="server" ID="odsCajas" SelectMethod="GetCajaPorId" TypeName="HQB.HQBDOC.HQBDocBLL.Orden.OrdenManagerBLL"> <SelectParameters> <asp:ControlParameter ControlID="hfCajaId" DefaultValue="" Name="cajaId" PropertyName="Value" Type="String" /> </SelectParameters> </asp:ObjectDataSource>private void LoadData() { try{ rgCajas.Columns.Clear(); string cajas_query_attributes = GetVariableLocal("cajas.query.attributes"); string[] arrCajas_query_attributes = cajas_query_attributes.Split(",".ToArray()); for (int i = 0; i < arrCajas_query_attributes.Length; i++) { string attibute = arrCajas_query_attributes[i].ToString(); string[] arrCajas_query_attributesField = attibute.Split("$".ToArray()); GridBoundColumn column = new GridBoundColumn(); column.HeaderText = arrCajas_query_attributesField[1]; column.DataField = arrCajas_query_attributesField[0]; rgCajas.MasterTableView.Columns.Add(column); } } catch (Exception ex) { //LOG.DE.ERRORES. LogManagerBLL.IngresarLog(LogConstante.ERROR, ex.Message, ex.StackTrace); throw ex; } }this is how I load dynamically the columns I get from a local variable is an array of string.
do not know if this will be the right approach?