I have a simple .NET datatable. I want to export the data to an excel. I would like to use an ultrawingrid to do the export.
Here is the code...
UltraGrid
ultradg = new UltraGrid();
ultradg.DataSource = table;
ultradg.DataBind();
UltraGridExcelExporter
ultraGridExcelExporter1= new UltraGridExcelExporter();
this.ultraGridExcelExporter1.Export(ultradg, path);
Seems simple enough..But it doesnt export any data..The datatable has got data...
Thanks a lot. It solved my problem..
This grid was not part of a form...I was using it just as a container for exporting to excel...So I had to create a new binding context...
Hi,
It's probably because the grid has no BindingContext. Since you are creating a grid in code and never parenting it to a form, it has no context for data binding.
Not parenting the grid to a form also means that it will never get disposed (unless you dispose it).
So it's generally good practice to add the grid to the Controls collection of a form. The form will dispose the grid when the form itself is disposed and this will provide a BindingContext.
Another option would be to simply set the grid.BindingContext to the form.BindingContext of any form you happen to have access to.
Or, as a last resort, you could simply set grid.BindingContext to a new BindingContext.
Sorry... I think the code was not readable..Here is it again
UltraGrid ultradg = new UltraGrid();ultradg.DataSource = table; ultradg.DataBind();
UltraGridExcelExporter ultraGridExcelExporter1= new UltraGridExcelExporter();