Set DetailTableView Datasource to empty

3 posts, 0 answers
  1. Angie
    Angie avatar
    101 posts
    Member since:
    Jan 2008

    Posted 20 Aug 2008 Link to this post

    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. Kiara
    Kiara avatar
    309 posts
    Member since:
    Jul 2006

    Posted 22 Aug 2008 Link to this post

    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
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Steve
    Steve avatar
    24 posts
    Member since:
    Jun 2010

    Posted 09 Oct 2013 Link to this post

    This solution did the trick for me, thanks.
Back to Top