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

Programmatic CardView Template and Datasource Problem

1 Answer 146 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Austin McDaniel
Top achievements
Rank 1
Austin McDaniel asked on 22 Jul 2008, 04:18 PM
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);  
                }  
            }  
        } 

1 Answer, 1 is accepted

Sort by
0
Yavor
Telerik team
answered on 25 Jul 2008, 05:13 AM
Hello Austin,

Can you please post a little bit more details on the setup which you have at your end. In which event are you creating the control's structure? Are there any other settings of importance? Also, you can consider opening a formal support ticket, and sending us a small project, demonstrating the case, for additional revision.

Kind regards,
Yavor
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
Grid
Asked by
Austin McDaniel
Top achievements
Rank 1
Answers by
Yavor
Telerik team
Share this question
or