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

master/detail; items in childitem.nestedtableview

3 Answers 202 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Knut
Top achievements
Rank 1
Knut asked on 14 Jan 2010, 10:22 PM

Hello,
This may have been answered many times, but after hours of googling I'm still in the dark.
I have a details table within a MasterRadGrid.MasterTableView - the details table databinds with the main grid ondetailtabledatabind and the detail table[s] display data just fine.

I need to read values from any or all of these detail tableviews, and in codebehind I have:

foreach (GridDataItem mRow in rGrd_recentAlbums.Items)  
    {  
    GridTableView licDet = (GridTableView)mRow.ChildItem.NestedTableViews[0];  
            foreach (GridDataItem dRow in licDet.Items)  
              { 
                ...code...
              }
    }

Now, what has me completely confused: I see the detailtableview databound/ the correct data when expanding any of the master grid rows. Debugging, looking at the GridTableView licDet, I see the expected name of it, I see the expected datakey values from both tableviews - yet, when I try to iterate the 
        foreach (GridDataItem dRow in licDet.Items)  
licDet has 0 items!?

Can someone please help me get past this?
Thanks,
knutb

3 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 15 Jan 2010, 08:05 AM
Hello Knut,

You can either set the HierarchyLoadMode property for the MasterTableView to Client and use your code so as to retrieve the child item values OR  temporarily expand the parent items, retrieve the child item values and collapse the parent items as shown in the following code:
c#:
       foreach (GridDataItem mRow in rGrd_RecentAlbums.MasterTableView.Items)   
       { 
           mRow.Expanded = true
            GridTableView licDet = (GridTableView)mRow.ChildItem.NestedTableViews[0]; 
             
            foreach (GridDataItem dRow in licDet.Items)   
              { 
                  string text = dRow["BoundColumnUniqueName"].Text; 
              } 
            mRow.Expanded = false
       }     

Thanks
Princy.
0
Knut
Top achievements
Rank 1
answered on 15 Jan 2010, 09:58 AM
Hello Princy,

Thank you very much for your response - it got me going in the right direction to resolve this with your mention of the item.expanded property. I could have been more specific in describing my goal, I think, so if anyone else gets stuck on this, here's the deal:
(This may be prefectly obvious to most people in this forum, but I did Google at lot to no avail last night...)

For each item in the master grid, if necessary, I [can] expand to see a details table where I have among other things a radiobuttonlist to set values for an update action on the datakey of the master grid item. The detail table databinds on the master grid 
DetailTableDataBind event. Thus, I need to iterate the items of the master grid, but it's only the parent item of the databound detail table that is of interest:
foreach (GridDataItem mRow in MasterGrid.Items)  
 

 

Now, thanks to Princy's reply, I added:     

 

if (mRow.Expanded == true) //!! and that's the key!  
 

Then, when I say

GridTableView DetailGrid = (GridTableView)mRow.ChildItem.NestedTableViews[0];   
 foreach (GridItem dRow in DetailGrid.Items)  
 

the GridItem dRow has items from which I can pull values for my update action:   

        string[] updatepmtrs = new string[3];   
    foreach (GridDataItem mRow in MasterGrid.Items)    
            {     
                if (mRow.Expanded == true)  //!! and that's the key!!   
              {     
              GridTableView DetailGrid = (GridTableView)mRow.ChildItem.NestedTableViews[0];     
              foreach (GridItem dRow in DetailGrid.Items)     
                {     
                RadioButtonList listRules = (RadioButtonList)dRow.FindControl("myradiobuttonlist for setting values");     
                updatepmtrs[0] = mRow.GetDataKeyValue("relevant keyid of master grid").ToString();   
                updatepmtrs[1] = DetailGrid.Items[dRow.ItemIndex].GetDataKeyValue("relevant keyid of detail grid").ToString();     
                updatepmtrs[2] = listRules.SelectedValue;    
                }  
              }  
            }  

 
(For my purposes, it also makes sense to ensure that only the mastergrid item that I'm currently looking to upgrade is expanded:

    protected void MasterGrid_ItemCommand(object source, GridCommandEventArgs e)  
      {  
      if (e.CommandName == RadGrid.ExpandCollapseCommandName)  
        {  
 
        foreach (GridItem item in e.Item.OwnerTableView.Items)  
            {  
            if (item.Expanded && item != e.Item)  
              {  
              item.Expanded = false;  
              }  
            }  
        }  
      } 
)
Thanks,
knut

 

 

 

 

 

0
suman
Top achievements
Rank 1
answered on 07 Aug 2012, 06:42 AM
thanks. It helps!
Tags
Grid
Asked by
Knut
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Knut
Top achievements
Rank 1
suman
Top achievements
Rank 1
Share this question
or