Search code examples
exceltelerikexporttelerik-gridradgrid

Export Telerik RadGrid with EditMode lines


I need to export a RadGrid table, and it contains several EditMode lines. I would like to choose which content to export or ideally, if possible, change the lines to

EditMode = false

before exporting, so it looks how I need.


Code Details: I have a few GridTemplateColumn, here is one of them:

<telerik:GridTemplateColumn
     ItemStyle-Wrap="false" UniqueName="DataInicioAtividade"
     DataField="DataInicioAtividade" HeaderText="*Data Inicio">
    <ItemTemplate>
        <telerik:RadDatePicker runat="server" ID="data_inicio" MinDate="1900/1/1">
            <DateInput runat="server"
                       CssClass="date-picker" ID="rad_dateInput_data_inicio"
                       MaxLength="10" CausesValidation="true" />
        </telerik:RadDatePicker>
    </ItemTemplate>
</telerik:GridTemplateColumn>

And a button that simply executes the code:

rgd_grid_naoiniciada.ExportExcel();

The problem is, as it looks, telerik RadGrid exporting just dumps the HTML code of the resulting table to an Excel file. The behaviour of the component is just like it should be, but the resulting file should have the field values, instead of HTML code containing input fields, links, images of RadCalendar etc...

Thanks in advance.


Solution

  • When you export Set the Templatecolumn values to the text property of Template column and then give ExportOnlyData="true";

    This will work for Template columns also now.

    In ItemBoundEvent, give the following code.

    protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
    {
     if ((isExport) && (e.Item is GridDataItem))
     {
       GridDataItem item = e.Item as GridDataItem;
        item["DataInicioAtividade"].Text = ((RadDatePicker)item["DataInicioAtividade"].FindControl("data_inicio")).SelectedDate.ToString();               
     }
    }