I have a self-referencing grid that I created by copying a Telerik example and modifying a few fields to match my application. When I look at the data table that is being used for the grid, I have 444 rows. I checked the first row and there are columns for the datakeys that I have defined and there is data in the columns. However, when the grid loads, it just says "No data to display". Here is my code:
| <telerik:RadGrid ID="RadGrid1" runat="server" Skin="Outlook" OnColumnCreated="RadGrid1_ColumnCreated" |
| OnItemCreated="RadGrid1_ItemCreated" OnItemDataBound="RadGrid1_ItemDataBound" |
| GridLines="None" OnNeedDataSource="RadGrid1_NeedDataSource"> |
| <MasterTableView CommandItemDisplay="None" HierarchyDefaultExpanded="true" HierarchyLoadMode="Client" |
| AllowSorting="false" DataKeyNames="OrganizationID, ParentOrganizationID" Width="100%" AutoGenerateColumns="False"> |
| <SelfHierarchySettings ParentKeyName="ParentOrganizationID" KeyName="OrganizationID" MaximumDepth="5" /> |
| <RowIndicatorColumn> |
| <HeaderStyle Width="20px"></HeaderStyle> |
| </RowIndicatorColumn> |
| <ExpandCollapseColumn> |
| <HeaderStyle Width="20px"></HeaderStyle> |
| </ExpandCollapseColumn> |
| <Columns> |
| <telerik:GridBoundColumn DataField="OrganizationID" HeaderText="OrganizationID" |
| ReadOnly="True" UniqueName="OrganizationID"> |
| </telerik:GridBoundColumn> |
| <telerik:GridBoundColumn DataField="Total" HeaderText="Total" UniqueName="Total"> |
| </telerik:GridBoundColumn> |
| </Columns> |
| </MasterTableView> |
| <ClientSettings AllowExpandCollapse="true" /> |
| <FilterMenu Skin="Outlook" EnableTheming="True"> |
| <CollapseAnimation Type="OutQuint" Duration="200"></CollapseAnimation> |
| </FilterMenu> |
| </telerik:RadGrid> |
| protected void Page_Load(object sender, EventArgs e) |
| { |
| if (Assembly.GetAssembly(typeof(ScriptManager)).FullName.IndexOf("3.5") != -1) |
| { |
| RadGrid1.MasterTableView.FilterExpression = @"it[""ParentOrganizationID""] = Convert.DBNull"; |
| } |
| else |
| { |
| RadGrid1.MasterTableView.FilterExpression = "ParentOrganizationID IS NULL"; |
| } |
| } |
| protected void RadGrid1_ColumnCreated(object sender, Telerik.Web.UI.GridColumnCreatedEventArgs e) |
| { |
| if (e.Column is GridExpandColumn) |
| { |
| e.Column.Visible = false; |
| } |
| else if (e.Column is GridBoundColumn) |
| { |
| e.Column.HeaderStyle.Width = Unit.Pixel(100); |
| } |
| } |
| protected void RadGrid1_ItemCreated(object sender, Telerik.Web.UI.GridItemEventArgs e) |
| { |
| //Hide headers without MasterTableView's header |
| if (e.Item is GridHeaderItem && e.Item.OwnerTableView != RadGrid1.MasterTableView) |
| { |
| e.Item.Style["display"] = "none"; |
| } |
| if (e.Item is GridNestedViewItem) |
| { |
| e.Item.Cells[0].Visible = false; |
| } |
| } |
| protected void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e) |
| { |
| //Create Expand/Collapse button for each table view |
| CreateExpandCollapseButton(e.Item, "OrganizationID"); |
| } |
| public void CreateExpandCollapseButton(GridItem item, string columnUniqueName) |
| { |
| if (item is GridDataItem) |
| { |
| if (item.FindControl("MyExpandCollapseButton") == null) |
| { |
| Button button = new Button(); |
| button.Click += new EventHandler(button_Click); |
| button.CommandName = "ExpandCollapse"; |
| button.CssClass = (item.Expanded) ? "rgCollapse" : "rgExpand"; |
| button.ID = "MyExpandCollapseButton"; |
| if (item.OwnerTableView.HierarchyLoadMode == GridChildLoadMode.Client) |
| { |
| string script = String.Format(@"$find(""{0}"")._toggleExpand(this, event); return false;", item.Parent.Parent.ClientID); |
| button.OnClientClick = script; |
| } |
| int level = item.ItemIndexHierarchical.Split(':').Length; |
| if (level > 1) |
| { |
| button.Style["margin-left"] = level + 10 + "px"; |
| } |
| TableCell cell = ((GridDataItem)item)[columnUniqueName]; |
| cell.Controls.Add(button); |
| cell.Controls.Add(new LiteralControl(" ")); |
| cell.Controls.Add(new LiteralControl(((GridDataItem)item).GetDataKeyValue(columnUniqueName).ToString())); |
| } |
| } |
| } |
| public void Page_PreRenderComplete(object sender, EventArgs e) |
| { |
| HideExpandColumnRecursive(RadGrid1.MasterTableView); |
| } |
| public void HideExpandColumnRecursive(GridTableView tableView) |
| { |
| GridItem[] nestedViewItems = tableView.GetItems(GridItemType.NestedView); |
| foreach (GridNestedViewItem nestedViewItem in nestedViewItems) |
| { |
| foreach (GridTableView nestedView in nestedViewItem.NestedTableViews) |
| { |
| nestedView.Style["border"] = "0"; |
| Button MyExpandCollapseButton = (Button)nestedView.ParentItem.FindControl("MyExpandCollapseButton"); |
| if (nestedView.Items.Count == 0) |
| { |
| if (MyExpandCollapseButton != null) |
| { |
| MyExpandCollapseButton.Style["visibility"] = "hidden"; |
| } |
| nestedViewItem.Visible = false; |
| } |
| else |
| { |
| if (MyExpandCollapseButton != null) |
| { |
| MyExpandCollapseButton.Style.Remove("visibility"); |
| } |
| } |
| if (nestedView.HasDetailTables) |
| { |
| HideExpandColumnRecursive(nestedView); |
| } |
| } |
| } |
| } |
| protected void button_Click(object sender, EventArgs e) |
| { |
| ((Button)sender).CssClass = (((Button)sender).CssClass == "rgExpand") ? "rgCollapse" : "rgExpand"; |
| } |
| protected void RadGrid1_NeedDataSource(object source, GridNeedDataSourceEventArgs e) |
| { |
| RadGrid1.DataSource = MyDataTable; |
| } |
| private DataTable MyDataTable |
| { |
| get |
| { |
| object obj = Session["GridData"]; |
| if ((!(obj == null))) |
| { |
| return ((DataTable)(obj)); |
| } |
| DataTable myDataTable = GetDataTable(); //call to service layer - returns 444 rows |
| Session["GridData"] = myDataTable; |
| return myDataTable; |
| } |
| } |