Hi -
I am having a problem exporting hierarchical data from an UltraWebGrid to Excel in one scenario: When the first parent row has no children. It took me a while to figure out what the problem was. Basically I have one on-screen grid with paging that shows the records fine in all scenarios. Since it has paging, when the user clicks an Export button I create a second, non-paged grid in code and pass that to the Excel exporter control. However, when I bind the hierarchical DataSet to the programmatically created grid, I get an "Object reference not set to an instance of an object" error *only* if the first row has no children.
To illustrate the problem I created a simple console app that uses a manually created DataSet that I borrowed from an Infragistics How To article. This is the whole thing:
using System;using System.Data;using System.Diagnostics;
//the project also needs references to System.Xml and Infragistics.WebUI.Shared
using Infragistics.WebUI.UltraWebGrid;namespace GridExportProblem{ class Program { private enum ChildRowMode { AllHaveChildren, FirstHaveChildren, LastHaveChildren } static void Main(string[] args) { CreateGrid(ChildRowMode.AllHaveChildren); CreateGrid(ChildRowMode.FirstHaveChildren);
//this blows up
CreateGrid(ChildRowMode.LastHaveChildren); } private static void CreateGrid(ChildRowMode childRowMode) { DataSet ds = GetDataset(childRowMode); UltraWebGrid uwg = new UltraWebGrid("myGrid"); // Set the WebGrid's view type to Hierarchical uwg.DisplayLayout.ViewType = Infragistics.WebUI.UltraWebGrid.ViewType.Hierarchical; uwg.DataSource = ds.Tables["Customer"]; Debug.WriteLine("Binding grid with ChildRowMode " + childRowMode.ToString()); try { uwg.DataBind(); Debug.WriteLine("Success!"); } catch (Exception ex) { Debug.WriteLine("Failure. Error: " + ex.Message); Debug.WriteLine(ex.StackTrace); } } private static DataSet GetDataset(ChildRowMode childRowMode) { DataSet ds = new DataSet(); // Customer DataTable DataTable dt = new DataTable("Customer"); dt.Columns.Add("CustomerID", typeof(int)); dt.Columns.Add("CustomerName", typeof(string)); dt.Columns.Add("Date", typeof(DateTime)); dt.Rows.Add(new object[] { 1, "John Lever", DateTime.Now }); dt.Rows.Add(new object[] { 2, "Walter Smith", DateTime.Now.AddDays(1) }); dt.Rows.Add(new object[] { 3, "Kathy Lever", DateTime.Now.AddDays(2) }); dt.Rows.Add(new object[] { 4, "George Wills", DateTime.Now.AddDays(3) }); ds.Tables.Add(dt); // Orders DataTable dt = new DataTable("Orders"); dt.Columns.Add("OrderID", typeof(int)); dt.Columns.Add("ProductName", typeof(string)); dt.Columns.Add("Price", typeof(double)); dt.Columns.Add("Quantity", typeof(int)); if ((childRowMode == ChildRowMode.FirstHaveChildren) || (childRowMode == ChildRowMode.AllHaveChildren)) { dt.Rows.Add(new object[] { 1, "Bolts", 2.30, 15 }); dt.Rows.Add(new object[] { 1, "Screws", 2.03, 55 }); dt.Rows.Add(new object[] { 1, "Nails", 1.01, 25 }); dt.Rows.Add(new object[] { 2, "Bolts", 2.30, 65 }); dt.Rows.Add(new object[] { 2, "Screws", 2.03, 75 }); dt.Rows.Add(new object[] { 2, "Nails", 1.01, 95 }); } if ((childRowMode == ChildRowMode.LastHaveChildren) || (childRowMode == ChildRowMode.AllHaveChildren)) { dt.Rows.Add(new object[] { 3, "Bolts", 2.30, 65 }); dt.Rows.Add(new object[] { 3, "Screws", 2.03, 205 }); dt.Rows.Add(new object[] { 3, "Nails", 1.01, 265 }); dt.Rows.Add(new object[] { 4, "Bolts", 2.30, 695 }); } ds.Tables.Add(dt); // Create customers/orders relationship and add to DataSet ds.Relations.Add("Customer_Order", ds.Tables["Customer"].Columns["CustomerID"], ds.Tables["Orders"].Columns["OrderID"]); return ds; } }}
I'm the original poster. The problem was that I was creating a grid programmatically for Excel export purposes and the grid did not exist on a web page. In my support case, Infragistics agreed it was a problem but said that creating the control completely programmatically was not a supported use, and that I should place a control on the page, hide it, and reference it in code. I'm pretty sure this solved my problem.
(Note that the console app above was just to illustrate the issue. My original issue involved a web app.)
If you are seeing this problem even in a control that's on an aspx page, it may be a different issue.
I am using infragistics 2008 vol2 .net 3.5 version and running into
this issue (of child rows not getting populated when the first row does not have children). What do i have
to do to get this issue fixed.
Hello John,
Yes, we've changed our HotFix notifacations policy a bit - the information is now available in our public forums in a special HotFix subforum. For example, our latest HotFix (released just a few days ago) is announced here:
http://forums.infragistics.com/forums/t/19421.aspx
As some of you have requested before, a list of all the fixes in this release is included in the zip file along with the installer so you can have an idea of what's in it and decide if you want to install it or not.
HTH,
Hi Tony -
We're actually using 2008v3 for CLR 3.5. I installed the latest service pack (v.8.3.20083.2021) but I still have the problem. I'll file a support case.
Out of curiosity, do you know where I can find release notes that list which bugs were fixed in a given hot fix?
Thanks,
John
John,
I'm quite certain this was fixed in the first hotfix after the 2008 Volume 2 release. You can go to the Keys and Downloads page on www.infragistics.com and download the latest hotfix.
-Tony