I am trying to use the self-referencing hierarchy functionality of the grid but can't seem to get it to work properly. I even tried copying the code directly from the tutorial specified here verbatim into a new page and I continually get the same error: "No property or field 'ParentID' exists in type 'DataRowView'."
My application has the following grid definition:
When I run it against my data source, the grid binds great and even has the hierarchy as I would expect with one exception - ALL records are displayed as if they are parent records in addition to the one record that should be a parent record (which has all records again as children). I need to get rid of all the "top elements" with the exception of the one that is really supposed to be the parent. In the future multiple top-level parent elements will exist (all with a NETT_IS_ID value of 0), but currently only one does.
I tried using FilterExpressions, but even when I use the sample code provided from the Knowledge Base, it doesn't run. It just tells me the column NETT_IS_ID doesn't exist in the dataview, even though I can bind to it directly and it does in fact exist.
In case it helps, here is my code-behind:
Any suggestions?
My application has the following grid definition:
| <telerik:RadGrid ID="RadGrid2" runat="server" Skin="" Width= "97%" OnNeedDataSource= "RadGrid2_NeedDataSource" GridLines="None" ShowHeader="False"> | |
| <MasterTableView HierarchyDefaultExpanded="True" HierarchyLoadMode="Client" DataKeyNames= "NETT_ID,NETT_IS_ID" Width="100%" AutoGenerateColumns="False"> | |
| <SelfHierarchySettings ParentKeyName="NETT_IS_ID" KeyName="NETT_ID" MaximumDepth="0" /> | |
| <Columns> | |
| <telerik:GridBoundColumn HeaderText="NETT_ID" DataField="NETT_ID" /> | |
| <telerik:GridBoundColumn HeaderText="NETT_IS_ID" DataField="NETT_IS_ID" /> | |
| <telerik:GridBoundColumn HeaderText="Intermediate Stock" DataField="NETT_PRODUCT" /> | |
| </Columns> | |
| </MasterTableView> | |
| </telerik:RadGrid> |
When I run it against my data source, the grid binds great and even has the hierarchy as I would expect with one exception - ALL records are displayed as if they are parent records in addition to the one record that should be a parent record (which has all records again as children). I need to get rid of all the "top elements" with the exception of the one that is really supposed to be the parent. In the future multiple top-level parent elements will exist (all with a NETT_IS_ID value of 0), but currently only one does.
I tried using FilterExpressions, but even when I use the sample code provided from the Knowledge Base, it doesn't run. It just tells me the column NETT_IS_ID doesn't exist in the dataview, even though I can bind to it directly and it does in fact exist.
In case it helps, here is my code-behind:
| protected void Page_Load(object sender, EventArgs e) | |
| { | |
| site mstr = (site)this.Master; | |
| mstr.PageHeader = "Intermediate Stock"; | |
| this.PreRenderComplete += new EventHandler(Page_PreRenderComplete); | |
| //this.BindData(); | |
| } | |
| DataTable BindData() | |
| { | |
| DataSet ds = new DataSet(); | |
| using (OracleConnection conn = new OracleConnection(ConfigurationManager.ConnectionStrings["IntermediateStock"].ConnectionString)) | |
| { | |
| using (OracleCommand cm = new OracleCommand()) | |
| { | |
| cm.Connection = conn; | |
| cm.CommandText = "IS_NETT.GET_PRODUCT_TREE"; | |
| cm.CommandType = CommandType.StoredProcedure; | |
| OracleParameter param = new OracleParameter(); | |
| param.Direction = ParameterDirection.Output; | |
| param.ParameterName = "IO_CURSOR"; | |
| param.OracleType = OracleType.Cursor; | |
| cm.Parameters.Add(param); | |
| using (OracleDataAdapter da = new OracleDataAdapter(cm)) | |
| { | |
| //da.TableMappings.Add("Table", "ISResults"); | |
| da.Fill(ds, "Table"); | |
| } | |
| } | |
| } | |
| DataColumn[] keys = new DataColumn[1]; | |
| keys[0] = ds.Tables[0].Columns["NETT_ID"]; | |
| ds.Tables[0].PrimaryKey = keys; | |
| return ds.Tables[0]; | |
| } | |
| protected void RadGrid1_NeedDataSource(object sender, GridNeedDataSourceEventArgs e) | |
| { | |
| this.RadGrid1.DataSource = this.BindData(); | |
| } | |
| protected void RadGrid2_NeedDataSource(object sender, GridNeedDataSourceEventArgs e) | |
| { | |
| this.RadGrid2.DataSource = this.BindData(); | |
| } | |
| public void Page_PreRenderComplete(object sender, EventArgs e) | |
| { | |
| HideExpandColumnRecursive(RadGrid1.MasterTableView); | |
| HideExpandColumnRecursive(RadGrid2.MasterTableView); | |
| } | |
| public void HideExpandColumnRecursive(GridTableView tableView) | |
| { | |
| GridItem[] nestedViewItems = tableView.GetItems(GridItemType.NestedView); | |
| foreach (GridNestedViewItem nestedViewItem in nestedViewItems) | |
| { | |
| foreach (GridTableView nestedView in nestedViewItem.NestedTableViews) | |
| { | |
| if (nestedView.Items.Count == 0) | |
| { | |
| TableCell cell = nestedView.ParentItem["ExpandColumn"]; | |
| cell.Controls[0].Visible = false; | |
| nestedViewItem.Visible = false; | |
| } | |
| if (nestedView.HasDetailTables) | |
| { | |
| HideExpandColumnRecursive(nestedView); | |
| } | |
| } | |
| } | |
| } | |
| } | |
| } | |
Any suggestions?