bind datasource to nested radgrid codebehind

2 posts, 0 answers
  1. Mike
    Mike avatar
    12 posts
    Member since:
    Mar 2013

    Posted 11 Apr 2013 Link to this post

    I'm trying to follow along with this demo

    However I want to bind the datasource of the first nested radgrid on the code behind.

    I thought it might be something like this but is it more complicated than this?
    RadGrid1.MasterTableView.DetailTables.radGrid2.DataSource = myDatasource;

    Also another question, when I bind to this nested grid (radGrid2), I send all records and the following code will filter or do I need to grab the ID on a method call within the radGrid1? If so please direct me to how to do accomplish this?
                                                    <telerik:GridRelationFields DetailKeyField="referenceID" MasterKeyField="referenceID"></telerik:GridRelationFields>

    radGrid1 shows all records, use the dropdown and show records in the radGrid2 that pertain to that ID of radGrid1.

    I foudn the following but get an error : on this line - (GridTableView)item.ChildItem.NestedTableViews[0]

    Index was outside the bounds of the array.

    protected void RadGrid1_PreRender(object sender, EventArgs e)
             using (var db = new E3TDataContext())
                 citationItems = db.Citations.ToList();
                 //RadGrid1.MasterTableView.DetailTables.radGrid2.DataSource = myDatasource;
             foreach (GridDataItem item in RadGrid1.MasterTableView.Items)
                 GridTableView nestedView = (GridTableView)item.ChildItem.NestedTableViews[0];
                 if (item["parentrowColumnUniqueName"].Text == "Text")
                     nestedView.DataSource = citationItems;
                 else if (item["parentrowColumnUniqueName"].Text != "Text")
                     nestedView.DataSource = citationItems;

  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 12 Apr 2013 Link to this post


    You can bind the inner grid in its NeedDataSource event as shown below.
    protected void RadGrid2_NeedDataSource(object source, GridNeedDataSourceEventArgs e)
          GridDataItem parentItem = ((sender as RadGrid).NamingContainer as GridNestedViewItem).ParentItem as GridDataItem;
          (sender as RadGrid).DataSource = GetDataTable("SELECT OrderID, EmployeeID, CustomerID FROM Orders where CustomerID='" + parentItem.GetDataKeyValue("CustomerID").ToString() + "'");
Back to Top