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

Set DetailTableView Datasource to empty

2 Answers 133 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Angie
Top achievements
Rank 1
Angie asked on 20 Aug 2008, 06:27 PM
I have a master grid to which I am binding a Detail grid only if it is part of a "series".  All other rows should not have a detail table.  There's no real key relationship between the master and detail table otherwise.

When I try to just bind the detail grid on only the rows which require it, it binds the entire master table view to the detail grid on the rows which don't.  I cannot get the detail grid to have a null datasource.

I don't know if I'm explaining it well, but how do I prevent the grid from showing the entire master table view on the detail view when there are no records to explicitly bind?

protected void RadGridCE_DetailTableDataBind(object source, Telerik.Web.UI.GridDetailTableDataBindEventArgs e)  
        {  
            GridDataItem dataItem = (GridDataItem)e.DetailTableView.ParentItem;  
 
            if (dataItem["is_series"].Text == "1")  
            {  
                int series_id = int.Parse(dataItem["series_id"].Text);  
                e.DetailTableView.DataSource = (FarranMedia.Classes.OnlineCE.CECourseGetBySeriesID(series_id)).Tables[0];  
            }  
            else  
            {  
 
                e.DetailTableView.DataSource = null;  
 
            }  
             
        } 

Thanks.

2 Answers, 1 is accepted

Sort by
0
Kiara
Top achievements
Rank 1
answered on 22 Aug 2008, 01:44 PM
Angie, I think that assigning an empty data source of objects inside the else statement should be sufficient, namely:

protected void RadGridCE_DetailTableDataBind(object source, Telerik.Web.UI.GridDetailTableDataBindEventArgs e)   
        {   
            GridDataItem dataItem = (GridDataItem)e.DetailTableView.ParentItem;   
  
            if (dataItem["is_series"].Text == "1")   
            {   
                int series_id = int.Parse(dataItem["series_id"].Text);   
                e.DetailTableView.DataSource = (FarranMedia.Classes.OnlineCE.CECourseGetBySeriesID(series_id)).Tables[0];   
            }   
            else   
            {   
  
                e.DetailTableView.DataSource = new Object[0];   
  
            }   
              
        }  

Hope this is helpful.

Kiara
0
Steve
Top achievements
Rank 1
answered on 09 Oct 2013, 04:45 PM
This solution did the trick for me, thanks.
Tags
Grid
Asked by
Angie
Top achievements
Rank 1
Answers by
Kiara
Top achievements
Rank 1
Steve
Top achievements
Rank 1
Share this question
or