This is a migrated thread and some comments may be shown as answers.

Export Radgrid template column with combobox and textbox

7 Answers 353 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Chriis
Top achievements
Rank 1
Chriis asked on 22 Sep 2014, 08:58 PM
Hi all,

I am trying to export a radgrid which contain multi template columns, most columns just contain a Label,  except two columns. One contain a combo box and the other is textbox.

When excel export button is clicked I want to export combobox.SelectedItem.Text and textbox.Text. I followed the following post's solution:
http://www.telerik.com/forums/exporting-a-radgrid-template-column-control-data-to-excel
but I still cannot get the text for the two special columns display on the excel file, where all other columns are fine without issue.

Thanks in advance.

-Chris

7 Answers, 1 is accepted

Sort by
0
Kostadin
Telerik team
answered on 25 Sep 2014, 09:45 AM
Hello Chriis,

If you are using an Html based export format (default one) the TextBox text should be exported automatically. Regards the issue with extorting RadComboBox control a possible solution is to add a Label which will be hidden, but its Text will be the same as the selected value of the RadComboBox. This way when you export the grid you will switch the visibility of both controls and the exported document will contains all the ComboBox values.

I hope this information helps.

Kostadin
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Chriis
Top achievements
Rank 1
answered on 02 Oct 2014, 07:40 PM
Hi Kostadin,

I got the export working ... but I cannot get the ignorePaging working... in the following code if I uncomment the ignorePaging=True then those dropdown and comment column will not export any data. Please help:

on HTML ....
<telerik:RadGrid AllowSorting="true" AllowFilteringByColumn="true" ID="radGridAcctLst" runat="server" AutoGenerateColumns="false" GridLines="None" ShowHeader="true" 
 AllowPaging="true" PageSize="50"
OnItemDataBound="radgridAcctLst_DataBound" 
OnNeedDataSource="radGridAcctLst_needDataSource"
OnUpdateCommand="radGridAcctLst_UpdateCommand"
OnDeleteCommand="radGridAcctLst_OnDelete"
OnInsertCommand="radGridAcctLst_OnInsert"
OnItemCommand="radGridAcctLst_ItemCommand"
>
<ClientSettings>
    <Resizing AllowColumnResize="true" />
</ClientSettings>

<ExportSettings ExportOnlyData="true"></ExportSettings>...


onItemCommand

protected void radGridAcctLst_ItemCommand(object sender, GridCommandEventArgs e)
{
  if (e.CommandName == RadGrid.ExportToExcelCommandName)
  {
      radGridAcctLst.MasterTableView.Columns[0].Visible = false;
      radGridAcctLst.MasterTableView.Columns[1].Visible = false;
      foreach (GridDataItem item in radGridAcctLst.MasterTableView.Items)
      {
          item["dropdownCol"].Text = ((RadComboBox)item["dropdownCol"].FindControl("comboControl")).SelectedItem.Text;
          item["commentCol"].Text = ((TextBox)item["comment"].FindControl("txtComment")).Text;
      }

      // radGridAcctLst.ExportSettings.IgnorePaging = true;
      radGridAcctLst.ExportSettings.FileName = "Export_" + DateTime.Now.ToString("yyyyMMdd");
      radGridAcctLst.ExportSettings.Excel.Format = (GridExcelExportFormat)Enum.Parse(typeof(GridExcelExportFormat), "Biff");
     

  }
}
0
Kostadin
Telerik team
answered on 07 Oct 2014, 07:53 AM
Hello Chriis,

If you want to persist the changes when IgnorePaging is enabled you need to use the approach from my previous reply. Generally to use a Label control which holds RadComboBox value. The reason is that when ExportToExcel is fired a built-in code loops through the grid's cells and try to set the cell text the similar as you did on ItemCommand event handler. The main issue is that the code could not retrieve the ComboBox text and leave those cells empty and remove the control from the cell. That's why the changes which you made on ItemCommand are not persisted and you could not set them later.

Regards,
Kostadin
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Chriis
Top achievements
Rank 1
answered on 07 Oct 2014, 04:04 PM
Hi Kostadin,

Please let me know in which event should I put the code to swap the visibility of the RadComboBox and the hidden label?

ItemCommand or Databound and try to detect the export command? If you can provide some sample it will be great.

Thanks,
Chris
0
Kostadin
Telerik team
answered on 10 Oct 2014, 10:36 AM
Hello Chriis,

A possible solution is to loop thought all data and set the Label text and also switch the visibility on ItemCommand. Basically you already done that in your code but instead setting the Text on the cell element you have to set it on the Label and show it.

Regards,
Kostadin
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Chriis
Top achievements
Rank 1
answered on 10 Oct 2014, 03:56 PM
Hi Kostadin,

I already tried this again same problem when I turn on ignore paging:

protected void radGridAcctLst_ItemCommand(object sender, GridCommandEventArgs e)
{
  if (e.CommandName == RadGrid.ExportToExcelCommandName)
  {
      radGridAcctLst.MasterTableView.Columns[0].Visible = false;
      radGridAcctLst.MasterTableView.Columns[1].Visible = false;
      foreach (GridDataItem item in radGridAcctLst.MasterTableView.Items)
      {
         ((RadComboBox)item["dropdownCol"].FindControl("comboControl")).Visible=false;
          ((Label)item["dropdownCol"].FindControl("lblselection")).Visible=true;
      }

      // radGridAcctLst.ExportSettings.IgnorePaging = true;
      radGridAcctLst.ExportSettings.FileName = "Export_" + DateTime.Now.ToString("yyyyMMdd");
      radGridAcctLst.ExportSettings.Excel.Format = (GridExcelExportFormat)Enum.Parse(typeof(GridExcelExportFormat), "Biff");
     

  }
0
Daniel
Telerik team
answered on 16 Oct 2014, 10:41 AM
Hello Chris,

The easiest way to export the contents of the RadComboBox would be to disable the ExportOnlyData property as it will remove the controls in the cell. You can find an old, but still working demo in the following forum thread:
Export Excel GridTemplateColumn + RadComboBox

Let me know if you need more information.

Regards,
Daniel
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
Grid
Asked by
Chriis
Top achievements
Rank 1
Answers by
Kostadin
Telerik team
Chriis
Top achievements
Rank 1
Daniel
Telerik team
Share this question
or