I am trying to create a hierarchy grid programmatically based on a xml file. I am successful in adding three hierarchies. It seems that there is some problem in the way I added the third hierarchy because the properties (font color, bold) i applied are not showing up in third hierarchy (strangely it shows up in second hierarchy and second hierarchy is created by same code block that created third hierarchy) . Also, when I added the fourth hierarchy it throws error in 'DetailTableDataBind' because it cannot find the datakey values in the third hierarchy. The code snippet is here.
| public void GenerateGrid(RadGrid radGrid1) |
| { //loading xml file |
| chartXml = XElement.Load(FilterPath, LoadOptions.PreserveWhitespace); |
| title = chartXml.Attribute("title").Value; |
| radGrid1.MasterTableView.PageSize = 10; |
| foreach (XElement chartElement in chartXml.Elements()) |
| { |
| if (chartElement.Name.LocalName != null && chartElement.Name.LocalName == "Filters") |
| { |
| if(chartElement.Attribute("referencePath") != null) |
| referencePath = chartElement.Attribute("referencePath").Value; |
| bool topFilter = true; |
| foreach (XElement filterElement in chartElement.Elements()) |
| { |
| if (topFilter) |
| { |
| radGrid1.MasterTableView.Width = Unit.Percentage(100); |
| radGrid1.MasterTableView.BorderWidth = 2; |
| radGrid1.MasterTableView.BorderColor = System.Drawing.Color.Red; |
| if(filterElement.Attribute("name") != null) |
| radGrid1.MasterTableView.Name = filterElement.Attribute("name").Value; |
| if(filterElement.Attribute("dataKeyNames") != null) |
| radGrid1.MasterTableView.DataKeyNames = filterElement.Attribute("dataKeyNames").Value.Split(','); |
| string[] columnNames = filterElement.Attribute("columns").Value.ToString().Split(','); |
| foreach (string columnName in columnNames) |
| { |
| GridBoundColumn boundColumn = new GridBoundColumn(); |
| radGrid1.MasterTableView.Columns.Add(boundColumn); |
| boundColumn.UniqueName = columnName; |
| boundColumn.DataField = columnName; |
| boundColumn.HeaderText = columnName; |
| } |
| lastAddedDetailTable = radGrid1; |
| topFilter = false; |
| } |
| else |
| { |
| GridTableView tableView = new GridTableView(radGrid1); |
| tableView.Width = Unit.Percentage(100); |
| tableView.Font.Bold = true; |
| tableView.BorderWidth = 2; |
| tableView.BorderColor = System.Drawing.Color.Red; |
| if (filterElement.Attribute("name") != null) |
| tableView.Name = filterElement.Attribute("name").Value; |
| if (filterElement.Attribute("dataKeyNames") != null) |
| tableView.DataKeyNames = filterElement.Attribute("dataKeyNames").Value.Split(','); |
| if (lastAddedDetailTable.ID == "RadGrid1") |
| { |
| radGrid1.MasterTableView.DetailTables.Add(tableView); |
| } |
| else |
| { |
| ((GridTableView)lastAddedDetailTable).DetailTables.Add(tableView); |
| } |
| string[] columnNames = filterElement.Attribute("columns").Value.ToString().Split(','); |
| foreach (string columnName in columnNames) |
| { |
| GridBoundColumn boundColumn = new GridBoundColumn(); |
| tableView.Columns.Add(boundColumn); |
| boundColumn.UniqueName = columnName; |
| boundColumn.DataField = columnName; |
| boundColumn.HeaderText = columnName; |
| } |
| lastAddedDetailTable = tableView; |
| } |
| } |
| } |
| } |
| } |
The sample xml file is this.
| <?xml version="1.0" encoding="utf-8" ?> |
| <Chart title="Customer Order Details"> |
| <Filters referencePath="GetCustomerOrders1"> |
| <Filter name="Customers" dataKeyNames="CustomerId" columns = "CustomerId,CustomerName,CustomerAddres" /> |
| <Filter name="Orders" dataKeyNames="OrderId" columns = "OrderId,OrderDate,CustomerId" /> |
| <Filter name="OrderDetails" dataKeyNames="ProductId" columns = "ProductId,OrderDetailsId,UnitPrice,ProductName" /> |
| <Filter name="ProductDetails" dataKeyNames="ProductId" columns = "ProductName,ProductDesc,ProductId" /> |
| </Filters> |
| </Chart> |
Help appreciated.
Thanks,
Gijo Joseph.