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

how to export programmatically without a webform control

1 Answer 56 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Timothy
Top achievements
Rank 1
Timothy asked on 05 Jul 2012, 11:06 PM
Hey, I am trying to figure out if it is possible to construct a grid and use the export to excel functionality without using it in a webform. I just want to get the functional feature of exporting without visually displaying it in the web. Is that possible?

I know there is a TelerikData.dll that contains ExportToExcelML, so I'm looking for something like that, but probably in the ASP.NET version...

Thanks!

1 Answer, 1 is accepted

Sort by
0
Eyup
Telerik team
answered on 10 Jul 2012, 04:41 PM
Hello Timothy,

One possible approach is to create the grid only when exporting is needed:
   mark-up:
<asp:PlaceHolder runat="server" ID="PlaceHolder1" />
   code-behind:
RadGrid grid = new RadGrid();
protected void Button1_Click(object sender, EventArgs e)
{
    DefineGridStructure();
    grid.MasterTableView.ExportToExcel();
}
private void DefineGridStructure()
{
    grid.ID = "RadGrid2";
    grid.DataSourceID = "SqlDataSource1";
    grid.Skin = "Vista";
    grid.Width = Unit.Percentage(100);
    grid.PageSize = 15;
    grid.AllowPaging = true;
    grid.PagerStyle.Mode = GridPagerMode.NextPrevAndNumeric;
    grid.AutoGenerateColumns = false;
    grid.MasterTableView.Width = Unit.Percentage(100);
    grid.MasterTableView.DataKeyNames = new string[] { "OrderID" };
    GridBoundColumn boundColumn = new GridBoundColumn();
    boundColumn.DataField = "OrderID";
    boundColumn.HeaderText = "Customer ID";
    grid.MasterTableView.Columns.Add(boundColumn);
    boundColumn = new GridBoundColumn();
    boundColumn.DataField = "ShipName";
    boundColumn.HeaderText = "Contact Name";
    grid.MasterTableView.Columns.Add(boundColumn);
}

Please refer to the following topic for additional details on creating the grid programmatically:
 RadGrid Programmatic Creation ( Section: Creating the grid entirely in the code behind )

An alternative approach would be to hide the grid with CSS:
<style type="text/css">
  .RadGrid
  {
      display:none;
  }
  </style>

That way the export functionality will work without the grid being displayed in the web page as requested.

Regards,
Eyup
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Tags
Grid
Asked by
Timothy
Top achievements
Rank 1
Answers by
Eyup
Telerik team
Share this question
or