This is a migrated thread and some comments may be shown as answers.

RadGrid inside of a RadGrid

10 Answers 254 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jim
Top achievements
Rank 1
Jim asked on 05 Jul 2008, 02:37 PM
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.

10 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 07 Jul 2008, 05:42 AM
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.
0
Jim
Top achievements
Rank 1
answered on 07 Jul 2008, 03:21 PM
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.
0
Sebastian
Telerik team
answered on 08 Jul 2008, 11:20 AM
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
0
Jim
Top achievements
Rank 1
answered on 08 Jul 2008, 02:56 PM

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.

0
Nikita Gourme
Top achievements
Rank 1
answered on 09 Jul 2008, 01:16 PM
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

0
Jim
Top achievements
Rank 1
answered on 09 Jul 2008, 03:10 PM
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.
0
Nikita Gourme
Top achievements
Rank 1
answered on 14 Jul 2008, 10:47 AM
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
0
Jim
Top achievements
Rank 1
answered on 14 Jul 2008, 01:59 PM
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.
0
Nikita Gourme
Top achievements
Rank 1
answered on 14 Jul 2008, 02:14 PM
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
0
pmessina
Top achievements
Rank 1
answered on 13 Aug 2008, 05:36 PM
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();  
 }
Tags
Grid
Asked by
Jim
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Jim
Top achievements
Rank 1
Sebastian
Telerik team
Nikita Gourme
Top achievements
Rank 1
pmessina
Top achievements
Rank 1
Share this question
or