RadGrid inside of a RadGrid

11 posts, 0 answers
  1. Jim
    Jim avatar
    5 posts
    Member since:
    Jul 2008

    Posted 05 Jul 2008 Link to this post

    I have created a RadGrid inside of a RadGrid, everything binds just fine, but when I want the put the embedded RadGrid into edit mode, nothing happens.  I think it's submitting the outer RadGrid as well.  What can I do to get around this?  Thanks.
  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 07 Jul 2008 Link to this post

    Hi Jim,

    Are you trying to put the Detail table in edit mode? Here is the code snippet to put the child table in edit mode on expanding the Master table.

    ASPX:
    <DetailTables > 
     <telerik:GridTableView  Name="Detail"  AllowPaging="true" PageSize="5"   DataSourceID="SqlDataSource1" > 
       <Columns> 
          <telerik:GridBoundColumn UniqueName="ProductName" HeaderText="ProductName" DataField="ProductName" > 
            </telerik:GridBoundColumn> 
          </Columns> 
        </telerik:GridTableView> 
    </DetailTables> 


    CS:
     protected void RadGrid1_PreRender(object sender, EventArgs e)  
        {  
            foreach (GridDataItem item in RadGrid1.Items)  
            {  
                if(item.OwnerTableView.Name == "Detail")   
                {  
                    item.Edit = true;  
                }  
            }  
            RadGrid1.Rebind();  
      } 

    Thanks
    Princy.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Jim
    Jim avatar
    5 posts
    Member since:
    Jul 2008

    Posted 07 Jul 2008 Link to this post

    No, I'm not using a detail table.  A simple example would be that I'm putting a table inside of another table's cell.  So take a bunch of say car makes (Ford, Dodge, Nissan, etc) in the main table.  Then the next cell is maybe a year the company was started.  Then the next cell is a table within say the Ford row that lists
    (Mustang,
    Taurus,
    Focus,
    etc)

    When I put the main RadGrid into edit mode all the cells are converted properly, checkboxes, textboxes, labels, etc.  The model table within the cell stays in view mode with the edit mode of the main grid (which is fine).  But when I click the edit link in the Model Grid, it does nothing.  It looks like it rebinds the main grid.  Is there any way to put (in this example) the model table into edit mode without submitting the entire grid?  I am not using expanding tables or detail tables.  Thanks.
  5. Sebastian
    Admin
    Sebastian avatar
    9934 posts

    Posted 08 Jul 2008 Link to this post

    Hi Jim,

    Do you use advanced binding through the NeedDataSource event or data source control for the nested grid? Thus the items should be switched into edit mode without any additional coding when clicking an arbitrary edit link from row belonging to the internal grid.

    Best regards,
    Stephen
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  6. Jim
    Jim avatar
    5 posts
    Member since:
    Jul 2008

    Posted 08 Jul 2008 Link to this post

    The needdatasource would make sense.  However, since it is tied to an item in the main radgrid, how could I create a datasource based on that in the needdatasource call.  There isn't an option for e.item, to find out which item to query in the needdatasource call.  Unless I'm missing something.

  7. Nikita Gourme
    Nikita Gourme avatar
    318 posts
    Member since:
    May 2006

    Posted 09 Jul 2008 Link to this post

    Sorry to interrupt but let me share my suggestion here. The path that I would choose is:
    • Fetch the source data for the grid item from the outer grid (inside its ItemDataBound handler) using the e.Item.DataItem object or using DataKeyNames/DataKeyValues. Thus you will be able to determine what type of grid you need inside the row and set a Cache or Session variable which to indicate that uniquely.
    • Get reference to the nested grid by calling e.Item.FindControl(gridId) method and call its Rebind() method.
    • Inside the NeedDataSource handler of the inner grid check the value for the Cache or Session variable and assign the source in conjunction with it.

    Nikita

  8. Jim
    Jim avatar
    5 posts
    Member since:
    Jul 2008

    Posted 09 Jul 2008 Link to this post

    Again, another great suggestion.  I am binding the grid using the e.item.findcontrol in the itemdatabound method.  And that works fine.  The problem is when you want to call the needdatasource, there is no way within that call to do an e.item.findcontrol to find that embedded grid.  I't binds just fine when the entire grid is loaded.  It's just when I click edit on that embedded grid that causes problems.  Do anyone have an example of how they might have acheived this?  Thanks again.
  9. Nikita Gourme
    Nikita Gourme avatar
    318 posts
    Member since:
    May 2006

    Posted 14 Jul 2008 Link to this post

    I am not sure whether you get the whole idea from my previous post - when you call the Rebind() method of the grid, it will automatically raise the NeedDataSource event and you will be able to bind it to data inside that handler. The edit operation for the nested grid will automatically raised the NeedDataSource event again and everything should be fine.

    Check this article for the RadGrid lifecycle as well.

    Nikita
  10. Jim
    Jim avatar
    5 posts
    Member since:
    Jul 2008

    Posted 14 Jul 2008 Link to this post

    I'm sorry I've tried a bunch of different things for this and I feel I can't focus properly.  What you said makes sense, but I think I've confused myself.  I hate to ask, but would it be possible to show an example?  Perhaps some code would help me see exactly how this is done.  Thanks so much.
  11. Nikita Gourme
    Nikita Gourme avatar
    318 posts
    Member since:
    May 2006

    Posted 14 Jul 2008 Link to this post

    Here are a couple of code excerpts which may put you on the right path, Jim:

    //ItemDataBound handler of the main grid  
    private void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)  
    {  
     if(e.Item is GridDataItem)  
     {  
       RadGrid nestedGrid = e.Item.FindControl("<MyNestedGridId>"as RadGrid;  
       Session["carId"] = (e.Item as GridDataItem).OwnerTableView.DataKeyNames[e.Item.ItemIndex]["<carId>"]. ToString();  
       nestedGrid.Rebind();  
     }  

    private void nestedGrid_NeedDataSource(object sender, Telerik.Web.UI.GridNeedDataSourceEventArgs e)  
    {  
      if(Session["carId"] != null)  
      {  
        string carID = Session["carId"as String;  
        switch(carID)    
        {  
          //cases here  
          //set the DataSource property for the grid based on the carId value  
        }  
      }  

    Hope this helps. Feel free to adjust the code accordingly.

    Nikita
  12. pmessina
    pmessina avatar
    13 posts
    Member since:
    Feb 2007

    Posted 13 Aug 2008 Link to this post

    Actually the code bellow is extremely close, but if you follow this example it will always place the last row of the table into the edit mode after update. It should read as below.

    if(e.Item is GridDataItem && e.Item.Edit)  
     {  
       RadGrid nestedGrid = e.Item.FindControl("<MyNestedGridId>"as RadGrid;  
       Session["carId"] = (e.Item as GridDataItem).OwnerTableView.DataKeyNames[e.Item.ItemIndex]["<carId>"]. ToString();  
       nestedGrid.Rebind();  
     }
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017