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

Deeply nested detail table fails to show data

1 Answer 61 Views
Grid
This is a migrated thread and some comments may be shown as answers.
David Russell
Top achievements
Rank 1
David Russell asked on 22 May 2010, 11:12 PM
I have a number of nested detail tables. All of the levels of nesting show data except the deepest level. I verified the DataReader being used contains the correct data, it simply doesn't show up.

using System;  
using System.Collections.Generic;  
using System.Linq;  
using System.Web;  
using System.Web.UI;  
using System.Web.UI.WebControls;  
using System.Data;  
using System.Data.Odbc;  
using Telerik.Web.UI;  
 
namespace preTOPS  
{  
    public partial class Home : System.Web.UI.Page  
    {  
        OdbcConnection connection;  
        User u = null;  
 
        protected override void OnInit(EventArgs e)  
        {  
            base.OnInit(e);  
 
            connection = Master.connection;  
 
            try 
            {  
                if (Session["user"] == null)  
                {  
                    u = new User();  
                    u.emailAddress = "foo@bar.com";  
 
                    //throw new Exception("@You must be logged in to view this page. Please <a href='Default.aspx' style='color:White; text-decoration:underline;'>login</a>.");  
                }  
                else 
                {  
                    u = (User)Session["user"];  
                }  
 
                DefineGridStructure();  
            }  
            catch (Exception ex)  
            {  
                MyUtilities.DoError(Master.maindiv, Master.errordiv, Master.lblError, ex, connection, null, Master.GetUserName());  
            }  
        }  
 
        protected void Page_Load(object sender, EventArgs e)  
        {  
            if (!Master.maindiv.Visible)  
                return;  
 
            RadGrid grid = (RadGrid)PlaceHolder1.FindControl("grid1");  
            RadAjaxManager1.AjaxSettings.AddAjaxSetting(grid, grid);  
 
        }  
 
        private void DefineGridStructure()  
        {  
            RadGrid grid = new RadGrid();  
            grid.ID = "grid1";  
 
            grid.CssClass = "maindiv";  
            grid.Width = Unit.Percentage(100);  
            grid.PageSize = 10;  
            grid.AllowPaging = true;  
//          grid.AllowSorting = true;  
//          grid.AllowFilteringByColumn = true;  
            grid.AllowAutomaticDeletes = true;  
            grid.AllowAutomaticInserts = true;  
            grid.AllowAutomaticUpdates = true;  
            grid.PagerStyle.Mode = GridPagerMode.NextPrevAndNumeric;  
            grid.AutoGenerateColumns = false;  
//          grid.GroupingEnabled = true;  
//          grid.ShowGroupPanel = true;  
//          grid.ShowStatusBar = true;  
//          grid.ClientSettings.AllowDragToGroup = true;  
            grid.NeedDataSource += new GridNeedDataSourceEventHandler(grid_NeedIndications);  
            grid.ItemCommand += new GridCommandEventHandler(grid_ItemCommand);  
            grid.ItemUpdated += new GridUpdatedEventHandler(grid_ItemUpdated);  
//          grid.MasterTableView.AllowFilteringByColumn = true;  
            grid.MasterTableView.PageSize = 15;  
            grid.MasterTableView.DataKeyNames = new string[] { "indication" };  
            grid.MasterTableView.CommandItemDisplay = GridCommandItemDisplay.Top;  
 
            GridEditCommandColumn e = new GridEditCommandColumn();  
            e.UniqueName = "IndicationEditButton";  
            e.ButtonType = GridButtonColumnType.ImageButton;  
            e.HeaderStyle.Width = Unit.Pixel(20);  
            grid.MasterTableView.Columns.Add(e);  
 
            GridBoundColumn c = new GridBoundColumn();  
            c.DataField = "indication";  
            c.HeaderText = "Indication";  
//          c.SortExpression = "indication";  
//          c.UniqueName = "indication";  
//          c.AllowSorting = true;  
//          c.AllowFiltering = true;  
//          c.DataType = System.Type.GetType("System.String");  
            grid.MasterTableView.Columns.Add(c);  
 
            GridButtonColumn b = new GridButtonColumn();  
            b.ConfirmText = "Confirm deletion of indication?";  
            b.ButtonType = GridButtonColumnType.ImageButton;  
            b.CommandName = "Delete";  
            b.CommandArgument = "indication";  
            b.UniqueName = "IndicationDeleteButton";  
            b.HeaderStyle.Width = Unit.Pixel(20);  
            b.Text = "Delete";  
            grid.MasterTableView.Columns.Add(b);  
 
//          grid.MasterTableView.GroupByExpressions.Add(new GridGroupByExpression("Indication Group By Indication"));  
 
 
            // PROTOCOLS  
 
            GridTableView tvProtocols = new GridTableView(grid);  
//          tvProtocols.AllowFilteringByColumn = true;  
            tvProtocols.Name = "Protocols";  
            tvProtocols.Width = Unit.Percentage(100);  
            tvProtocols.DataKeyNames = new string[] { "protocol" };  
            tvProtocols.CommandItemDisplay = GridCommandItemDisplay.Top;  
            //tvProtocols.AllowFilteringByColumn = true;  
//          tvProtocols.AllowSorting = true;  
//          tvProtocols.AllowMultiColumnSorting = true;  
//          tvProtocols.AllowPaging = true;  
            tvProtocols.AllowAutomaticDeletes = true;  
            tvProtocols.AllowAutomaticInserts = true;  
            tvProtocols.AllowAutomaticUpdates = true;  
 
            e = new GridEditCommandColumn();  
            e.UniqueName = "ProtocolEditButton";  
            e.ButtonType = GridButtonColumnType.ImageButton;  
            e.HeaderStyle.Width = Unit.Pixel(20);  
            tvProtocols.Columns.Add(e);  
 
            c = new GridBoundColumn();  
            c.DataField = "protocol";  
            c.HeaderText = "Protocol";  
//          c.SortExpression = "protocol";  
//          c.UniqueName = "protocol";  
//          c.AllowSorting = true;  
//          c.AllowFiltering = true;  
//          c.DataType = System.Type.GetType("System.String");  
            tvProtocols.Columns.Add(c);  
 
            c = new GridBoundColumn();  
            c.DataField = "sponsor";  
            c.HeaderText = "Sponsor";  
//          c.UniqueName = "sponsor";  
//          c.SortExpression = "sponsor";  
//          c.AllowSorting = true;  
//          c.AllowFiltering = true;  
//          c.DataType = System.Type.GetType("System.String");  
            tvProtocols.Columns.Add(c);  
 
            c = new GridBoundColumn();  
            c.DataField = "shorttitle";  
            c.HeaderText = "Short Title";  
//          c.AllowSorting = true;  
//          c.AllowFiltering = true;  
//          c.DataType = System.Type.GetType("System.String");  
            tvProtocols.Columns.Add(c);  
 
            c = new GridBoundColumn();  
            c.DataField = "cro";  
            c.HeaderText = "CRO";  
//          c.AllowSorting = true;  
//          c.AllowFiltering = true;  
//          c.DataType = System.Type.GetType("System.String");  
            tvProtocols.Columns.Add(c);  
 
            b = new GridButtonColumn();  
            b.ConfirmText = "Confirm deletion of protocol?";  
            b.ButtonType = GridButtonColumnType.ImageButton;  
            b.CommandName = "Delete";  
            b.CommandArgument = "protocol";  
            b.UniqueName = "ProtocolDeleteButton";  
            b.HeaderStyle.Width = Unit.Pixel(20);  
            b.Text = "Delete";  
            tvProtocols.Columns.Add(b);  
 
            GridRelationFields rf = new GridRelationFields();  
            rf.MasterKeyField = "indication";  
            rf.DetailKeyField = "indication";  
            tvProtocols.ParentTableRelation.Add(rf);  
 
 
            // STUDIES  
 
            GridTableView tvStudies = new GridTableView(grid);  
//          tvStudies.AllowFilteringByColumn = true;  
            tvStudies.Name = "Studies";  
            tvStudies.Width = Unit.Percentage(100);  
            tvStudies.DataKeyNames = new string[] { "protocol""site""facility" };  
//          tvStudies.AllowSorting = true;  
//          tvStudies.AllowMultiColumnSorting = true;  
//          tvStudies.AllowPaging = true;  
            tvStudies.CommandItemDisplay = GridCommandItemDisplay.Top;  
            tvStudies.AllowAutomaticDeletes = true;  
            tvStudies.AllowAutomaticInserts = true;  
            tvStudies.AllowAutomaticUpdates = true;  
 
            e = new GridEditCommandColumn();  
            e.UniqueName = "StudyEditButton";  
            e.ButtonType = GridButtonColumnType.ImageButton;  
            e.HeaderStyle.Width = Unit.Pixel(20);  
            tvStudies.Columns.Add(e);  
 
            c = new GridBoundColumn();  
            c.DataField = "site";  
            c.HeaderText = "Site";  
//          c.AllowFiltering = true;  
//          c.AllowSorting = true;  
//          c.DataType = System.Type.GetType("System.String");  
            tvStudies.Columns.Add(c);  
 
            c = new GridBoundColumn();  
            c.DataField = "facility";  
            c.HeaderText = "Facilities";  
//          c.AllowFiltering = true;  
//          c.AllowSorting = true;  
//          c.DataType = System.Type.GetType("System.String");  
            tvStudies.Columns.Add(c);  
 
            c = new GridBoundColumn();  
            c.DataField = "pi";  
            c.HeaderText = "PI";  
//          c.AllowFiltering = true;  
//          c.AllowSorting = true;  
//          c.DataType = System.Type.GetType("System.String");  
            tvStudies.Columns.Add(c);  
 
            c = new GridBoundColumn();  
            c.DataField = "status";  
            c.HeaderText = "Status";  
//          c.AllowFiltering = true;  
//          c.AllowSorting = true;  
//          c.DataType = System.Type.GetType("System.String");  
            tvStudies.Columns.Add(c);  
 
            c = new GridBoundColumn();  
            c.DataField = "firstcontact";  
            c.HeaderText = "First Contact";  
//          c.AllowFiltering = true;  
//          c.AllowSorting = true;  
//          c.DataType = System.Type.GetType("System.DateTime");  
            c.DataFormatString = "{0:MM/dd/yyyy}";  
            tvStudies.Columns.Add(c);  
 
            c = new GridBoundColumn();  
            c.DataField = "cdareceived";  
            c.HeaderText = "CDA Received";  
//          c.AllowFiltering = true;  
//          c.AllowSorting = true;  
//          c.DataType = System.Type.GetType("System.DateTime");  
            c.DataFormatString = "{0:MM/dd/yyyy}";  
            tvStudies.Columns.Add(c);  
 
            c = new GridBoundColumn();  
            c.DataField = "sqv";  
            c.HeaderText = "SQV";  
//          c.AllowFiltering = true;  
//          c.AllowSorting = true;  
//          c.DataType = System.Type.GetType("System.DateTime");  
            c.DataFormatString = "{0:MM/dd/yyyy}";  
            tvStudies.Columns.Add(c);  
 
            c = new GridBoundColumn();  
            c.DataField = "irbsubmission";  
            c.HeaderText = "IRB Submission";  
//          c.AllowFiltering = true;  
//          c.AllowSorting = true;  
//          c.DataType = System.Type.GetType("System.DateTime");  
            c.DataFormatString = "{0:MM/dd/yyyy}";  
            tvStudies.Columns.Add(c);  
 
            c = new GridBoundColumn();  
            c.DataField = "irbapproval";  
            c.HeaderText = "IRB Approval";  
//          c.AllowFiltering = true;  
//          c.AllowSorting = true;  
//          c.DataType = System.Type.GetType("System.DateTime");  
            c.DataFormatString = "{0:MM/dd/yyyy}";  
            tvStudies.Columns.Add(c);  
 
            c = new GridBoundColumn();  
            c.DataField = "siv";  
            c.HeaderText = "SIV";  
//          c.AllowFiltering = true;  
//          c.AllowSorting = true;  
//          c.DataType = System.Type.GetType("System.DateTime");  
            c.DataFormatString = "{0:MM/dd/yyyy}";  
            tvStudies.Columns.Add(c);  
 
            c = new GridBoundColumn();  
            c.DataField = "firstpatientenrolled";  
            c.HeaderText = "1st P Enrolled";  
//          c.AllowFiltering = true;  
//          c.AllowSorting = true;  
//          c.DataType = System.Type.GetType("System.DateTime");  
            c.DataFormatString = "{0:MM/dd/yyyy}";  
            tvStudies.Columns.Add(c);  
 
            c = new GridBoundColumn();  
            c.DataField = "lastpatientenrolled";  
            c.HeaderText = "Last P Enrolled";  
//          c.AllowFiltering = true;  
//          c.AllowSorting = true;  
//          c.DataType = System.Type.GetType("System.DateTime");  
            c.DataFormatString = "{0:MM/dd/yyyy}";  
            tvStudies.Columns.Add(c);  
 
            b = new GridButtonColumn();  
            b.ConfirmText = "Confirm deletion of study?";  
            b.ButtonType = GridButtonColumnType.ImageButton;  
            b.CommandName = "Delete";  
            b.CommandArgument = "study";  
            b.UniqueName = "StudyDeleteButton";  
            b.HeaderStyle.Width = Unit.Pixel(20);  
            b.Text = "Delete";  
            tvStudies.Columns.Add(b);  
 
            rf = new GridRelationFields();  
            rf.MasterKeyField = "protocol";  
            rf.DetailKeyField = "protocol";  
            tvStudies.ParentTableRelation.Add(rf);  
 
            // Comments  
 
            GridTableView tvComments = new GridTableView(grid);  
//          tvComments.AllowFilteringByColumn = true;  
            tvComments.Name = "Comments";  
            tvComments.Width = Unit.Percentage(100);  
            tvComments.DataKeyNames = new string[] { "studyid""commentmodified" };  
//          tvComments.AllowSorting = true;  
//          tvComments.AllowMultiColumnSorting = true;  
//          tvComments.AllowPaging = true;  
            tvComments.CommandItemDisplay = GridCommandItemDisplay.Top;  
            tvComments.AllowAutomaticDeletes = true;  
            tvComments.AllowAutomaticInserts = true;  
            tvComments.AllowAutomaticUpdates = true;  
 
            e = new GridEditCommandColumn();  
            e.UniqueName = "CommentEditButton";  
            e.ButtonType = GridButtonColumnType.ImageButton;  
            e.HeaderStyle.Width = Unit.Pixel(20);  
            tvComments.Columns.Add(e);  
 
            c = new GridBoundColumn();  
            c.DataField = "commentmodified";  
            c.HeaderText = "Last Modifed";  
//          c.AllowFiltering = true;  
//          c.AllowSorting = true;  
//          c.DataType = System.Type.GetType("System.DateTime");  
            c.DataFormatString = "{0:MM/dd/yyyy}";  
            tvComments.Columns.Add(c);  
 
            c = new GridBoundColumn();  
            c.DataField = "author";  
            c.HeaderText = "Modified By";  
//          c.AllowFiltering = true;  
//          c.AllowSorting = true;  
//          c.DataType = System.Type.GetType("System.String");  
            tvComments.Columns.Add(c);  
 
            c = new GridBoundColumn();  
            c.DataField = "comment";  
            c.HeaderText = "Comment";  
//          c.AllowFiltering = true;  
//          c.AllowSorting = true;  
//          c.DataType = System.Type.GetType("System.String");  
            tvComments.Columns.Add(c);  
 
            b = new GridButtonColumn();  
            b.ConfirmText = "Confirm deletion of comment?";  
            b.ButtonType = GridButtonColumnType.ImageButton;  
            b.CommandName = "Delete";  
            b.CommandArgument = "comment";  
            b.UniqueName = "CommentDeleteButton";  
            b.HeaderStyle.Width = Unit.Pixel(20);  
            b.Text = "Delete";  
            tvComments.Columns.Add(b);  
 
            rf = new GridRelationFields();  
            rf.MasterKeyField = "studyid";  
            rf.DetailKeyField = "studyid";  
            tvComments.ParentTableRelation.Add(rf);  
 
            tvStudies.DetailTables.Add(tvComments);  
            tvProtocols.DetailTables.Add(tvStudies);  
            grid.MasterTableView.DetailTables.Add(tvProtocols);  
 
            PlaceHolder1.Controls.Add(grid);  
        }  
 
        void grid_ItemUpdated(object source, GridUpdatedEventArgs e)  
        {  
        }  
 
        void grid_ItemCommand(object source, GridCommandEventArgs e)  
        {  
            if (e.CommandName == "Update")  
            {  
                if (e.Item is GridEditFormItem)  
                {  
                    GridEditFormItem gefi = (GridEditFormItem)e.Item;  
                }  
            }  
            else if (e.CommandName == "Insert")  
            {  
            }  
            else if (e.CommandName == "Delete")  
            {  
            }  
        }  
 
        void grid_NeedIndications(object source, GridNeedDataSourceEventArgs e)  
        {  
            OdbcCommand command1 = new OdbcCommand("select indication from indications order by indication asc;", connection);  
            OdbcDataReader reader1 = command1.ExecuteReader();  
            RadGrid grid = (RadGrid)PlaceHolder1.FindControl("grid1");  
            grid.DataSource = reader1;  
 
            OdbcCommand command2 = new OdbcCommand("select * from protocols;", connection);  
            OdbcDataReader reader2 = command2.ExecuteReader();  
            grid.MasterTableView.DetailTables[0].DataSource = reader2;  
 
            OdbcCommand command3 = new OdbcCommand("select * from studies;", connection);  
            OdbcDataReader reader3 = command3.ExecuteReader();  
            grid.MasterTableView.DetailTables[0].DetailTables[0].DataSource = reader3;  
 
            OdbcCommand command4 = new OdbcCommand("select * from comments;", connection);  
            OdbcDataReader reader4 = command4.ExecuteReader();  
            grid.MasterTableView.DetailTables[0].DetailTables[0].DetailTables[0].DataSource = reader4;  
        }  
 
    }  
}  
 

Thank you.

1 Answer, 1 is accepted

Sort by
0
Pavlina
Telerik team
answered on 27 May 2010, 09:44 AM
Hi David,

When binding each detail table view, RadGrid fires the DetailTableDataBind event. The argument for a DetailTableDataBind event handler carries all the information you need for binding the detail table, including the table view that should be bound, its parent item, and so on.

Examine the following demo and help article for details:
Hierarchical data-binding using DetailTableDataBind event
Programmatic Binding

Greetings,
Pavlina
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Tags
Grid
Asked by
David Russell
Top achievements
Rank 1
Answers by
Pavlina
Telerik team
Share this question
or