Server-side access to Radgrid and children in Template Column of Radgrid

6 posts, 0 answers
  1. Robert
    Robert avatar
    3 posts
    Member since:
    Nov 2011

    Posted 29 Dec 2011 Link to this post

    Hello,
     
    I have a Radgrid with another radgrid in an Editform template.

    An example of the structure below: 

    Radgrid1
        Editform Template
                    RadTab/multipage
                            Radgrid2
                                    Master Table
                                            Detail1
                                                Detail2

    I have a number things which I want to do server-side on the Details2 grid such as inserting footer fields, changing row colors etc.

    How do I access the Radgrid2 and children server side (only Radgrid1 appears as a directly accessable object).
    I'm new to ASP.Net programming so I'm probably missing something obvious. I'm used to dropping in a control and then being able to program against it server side immediately.

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

    Posted 30 Dec 2011 Link to this post

    Hello Robert,

    Try the following code.
    C#:
    protected void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
    {
     if (e.Item is GridEditableItem && e.Item.IsInEditMode)
     {
      GridEditableItem item = (GridEditableItem)e.Item;
      RadPageView page = (RadPageView)item.FindControl("RadPageView1");
      RadGrid grid=(RadGrid) page.FindControl("RadGrid2");
     }
    }

    -Shinu.
  3. Jayesh Goyani
    Jayesh Goyani avatar
    2733 posts
    Member since:
    May 2010

    Posted 30 Dec 2011 Link to this post

    Hello,

    After getting the grid you can access Detail table view by below code
    // Method 1
          foreach (GridDataItem item in RadGrid1.MasterTableView.Items)
          {
              if (item.HasChildItems)
              {
                  // if Detail1 and Detail2 are in same level
                  // for Detail1
                  foreach (GridDataItem citem in item.ChildItem.NestedTableViews[0].Items)
                  {
                       
                  }
     
                  //for Detail2
                  foreach (GridDataItem citem in item.ChildItem.NestedTableViews[1].Items)
                  {
     
                  }
     
                  //OR
                  // if Detail1 and Detail2 are NOT in same level
                  // for Detail1
                  foreach (GridDataItem citem in item.ChildItem.NestedTableViews[0].Items)
                  {
                      if (item.HasChildItems)
                      {
                          //for Details
                          foreach (GridDataItem citem2 in citem.ChildItem.NestedTableViews[0].Items)
                          {
     
                          }
                      }
                  }
              }
          }
           
     
          // Method 2
     
          foreach (GridDataItem item in RadGrid1.MasterTableView.Items)
          {
              // please give different for MasterTableView,DeTailTable
              if (item.OwnerTableView.Name == "GridName")
              {
     
              }
          }


    Thanks,
    Jayesh Goyani
  4. Robert
    Robert avatar
    3 posts
    Member since:
    Nov 2011

    Posted 30 Dec 2011 Link to this post

    Thanks Shinu,
    I'm using VB and using your code can find Radgrid6 however how do I access the details tables.
    As below on the 6th line of code I try to access the nested table view but "grid.MasterTableView.Items[0]" expects an identifier and "[0]" creates an error).

     

     

     

    Protected Sub RadGrid1_ItemDataBound(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridItemEventArgs) Handles RadGrid1.ItemDataBound
        If TypeOf e.Item Is GridEditableItem AndAlso e.Item.IsInEditMode Then
            Dim item As GridEditableItem = DirectCast(e.Item, GridEditableItem)
            Dim page As RadPageView = DirectCast(item.FindControl("RadPageView5"), RadPageView)
            Dim grid As RadGrid = DirectCast(page.FindControl("RadGrid6"), RadGrid)
            Dim nestedTableView as GridTableView = CType(grid.MasterTableView.Items[0], GridDataItem).ChildItem.NestedTableViews[0]
        End If
    End Sub

    Thanks a lot
    Robert

  5. Robert
    Robert avatar
    3 posts
    Member since:
    Nov 2011

    Posted 30 Dec 2011 Link to this post

    Thanks Jasesh,

    However I'm looking to access the children to a radgrid sitting in the editform template of Radgrid1 rather than the children of radgrid1 it self. I've managed to access these using the code here: http://www.telerik.com/help/aspnet-ajax/grid-traversing-detail-tables-items-in-grid.html

    Cheers
    Robert
  6. Ramya
    Ramya avatar
    2 posts
    Member since:
    Aug 2013

    Posted 04 Jan 2018 in reply to Jayesh Goyani Link to this post

    I have a RadGrid which has rows but when I try to read the rows in server side using following code, RadGridARSearch.MasterTableView.Items count is always zero. But Grid has one row with the checkbox checked.

    foreach (GridDataItem item in RadGridARSearch.MasterTableView.Items)
    {
    CheckBox chk = (CheckBox)item["ClientSelectColumn"].Controls[0];

     

    FYI..

    I tried even

    <telerik:RadAjaxManagerProxy ID="AjaxManagerProxy1" runat="server">
    <AjaxSettings>
    <telerik:AjaxSetting AjaxControlID="divFormatID">
    <UpdatedControls>
    <telerik:AjaxUpdatedControl ControlID="divFormatID" />
    </UpdatedControls>
    </telerik:AjaxSetting>
    </AjaxSettings>
    </telerik:RadAjaxManagerProxy>

    Can u help on this?

     

     

Back to Top