I am trying to implement a CardView Grid Programmaticly using an ITemplate and OnDemand Datasourcing and run into an error telling me that the datasource is null when I try to expand a detail table. I went ahead and implement a null check into the template to bypass the error but when this occurs EVERY table except for the one I expanded is empty. Below is my Programmic ITemplate for the Cardivew along with my RadGrid. Anyone have any ideas?
| public RadGrid SearchGrid |
| { |
| get |
| { |
| if (m_radGrid == null) |
| { |
| m_radGrid = new RadGrid(); |
| m_radGrid.ID = "searchGrid"; |
| m_radGrid.Skin = "Office2007"; |
| m_radGrid.ClientSettings.Resizing.AllowColumnResize = true; |
| m_radGrid.ClientSettings.AllowColumnsReorder = true; |
| //No Records Template |
| m_radGrid.MasterTableView.NoRecordsTemplate = new NoRecordsTemplate(); |
| //Row Format Template |
| if (m_view.RowFormat) |
| { |
| m_view.AllowSelect = false; //Don't Allow Selects on Row Format |
| m_radGrid.MasterTableView.ItemTemplate = new RowFormat(); |
| } |
| //Select Row Option |
| if (m_view.AllowSelect) |
| { |
| m_radGrid.AllowMultiRowSelection = true; |
| m_radGrid.ClientSettings.Selecting.AllowRowSelect = true; |
| m_radGrid.ClientSettings.Selecting.EnableDragToSelectRows = true; |
| m_radGrid.MasterTableView.Columns.Add(SelectColumn); |
| } |
| //Set options to allow Paging |
| m_radGrid.AllowPaging = true; |
| m_radGrid.PageSize = m_view.PageSize; |
| m_radGrid.PagerStyle.Mode = GridPagerMode.NextPrevAndNumeric; |
| m_radGrid.MasterTableView.HeaderStyle.CssClass = "GridMasterHeader"; |
| //Set options to enable Group-by |
| m_radGrid.AllowSorting = true; |
| m_radGrid.GroupingEnabled = true; |
| m_radGrid.ShowGroupPanel = false; |
| m_radGrid.ClientSettings.AllowDragToGroup = true; |
| m_radGrid.ClientSettings.AllowColumnsReorder = true; |
| //Heirachrcal data Demo |
| var tableViewArea = new GridTableView(m_radGrid); |
| tableViewArea.DataSource = msdl; |
| tableViewArea.HierarchyDefaultExpanded = false; |
| tableViewArea.Width = Unit.Percentage(100); |
| tableViewArea.HierarchyLoadMode = GridChildLoadMode.Client; |
| tableViewArea.ItemTemplate = new RowFormat(); |
| m_radGrid.MasterTableView.DetailTables.Add(tableViewArea); |
| //Data Sources |
| m_radGrid.NeedDataSource += NeedDataSource; |
| m_radGrid.DetailTableDataBind += DetailTableDataBind; |
| } |
| return m_radGrid; |
| } |
| set { m_radGrid = value; } |
| } |
| public class RowFormat : ITemplate |
| { |
| public void InstantiateIn(Control container) |
| { |
| var items = ((GridTableView)(container.Parent.NamingContainer)); |
| var RowIndex = ((GridDataItem)(container.NamingContainer)).ItemIndex; |
| if (items.DataSource != null) |
| { |
| var o = ((ArrayList) items.DataSource)[RowIndex]; |
| var properties = o.GetType().GetProperties(); |
| var tbl = new Table {CssClass = "CardviewTable"}; |
| foreach (var p in properties) |
| { |
| var row = new TableRow {CssClass = "CardviewRow", BorderWidth = 0}; |
| var cell1 = new TableCell {CssClass = "CardviewCol1", BorderWidth = 0}; |
| var cell2 = new TableCell {CssClass = "CardviewCol2", BorderWidth = 0}; |
| var col1 = new Label {Text = p.Name}; |
| var col2 = new Label {Text = p.GetValue(o, null).ToString()}; |
| cell1.Controls.Add(col1); |
| cell2.Controls.Add(col2); |
| row.Controls.Add(cell1); |
| row.Controls.Add(cell2); |
| tbl.Controls.Add(row); |
| } |
| container.Controls.Add(tbl); |
| } |
| } |
| } |