Remove plus sign for expanding detail table if unnecessary

11 posts, 0 answers
  1. Vinayak
    Vinayak avatar
    12 posts
    Member since:
    Apr 2008

    Posted 05 May 2008 Link to this post

    Hi,

    I have RadGrid with details table. It is showing plus sign on left side for every record in the grid.
    I don't want to show "+" sign for the records which do not have any child records. Currently if we expand by clicking "+" it is showing empty detail table structure.
    Is there any way to show "+" sign only for those records with child records associated with them?

    I have specified Master table/Detail table structure in .aspx. I am attaching datasource to both tables from code behind.

    Regards,
    Vinayak
  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 05 May 2008 Link to this post

    Hi Vinayak,

    Check out the following help doucment links.

    Hiding expand/collapse images when no records
    Hiding expand/collapse images when no records with HierarchyLoadMode = Client

    Hope this helps..
    Princy.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Puneet
    Puneet avatar
    3 posts
    Member since:
    Oct 2007

    Posted 05 May 2008 Link to this post

    Hi Princy,

    I had a similar situation and the links you provided really helped. I was able to hide the plus sign when there are no child records. However, when the page first loads, I see all the plus signs, and then when I click on any plus sign, its "fixed", i.e. it only shows plus signs when there is a child record. 
    Is there a way to hide the plus sign on first time load of the grid? I have AJAX enabled on the grid.

    Thanks,
    Puneet.  
  5. Kiara
    Kiara avatar
    309 posts
    Member since:
    Jul 2006

    Posted 06 May 2008 Link to this post

    If you alter the logic from the docs to wrap it inside !Page.IsPostBack conditional check and hide the expand/collapse button regardless whether the count of the child items is 0 or not, you should be done.

    Kiara
  6. Puneet
    Puneet avatar
    3 posts
    Member since:
    Oct 2007

    Posted 06 May 2008 Link to this post

    Hi Kiara,

    I dont seem to get it to work. Could you post a code sample (even if it is pseudo-code) to get me on the right track?

    Thanks,
    Puneet.   
  7. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 07 May 2008 Link to this post

    Hi Puneet,

    Try the above given code in the Page_Load event as Kiara pointed.

    CS:
     protected void Page_Load(object sender, EventArgs e) 
        { 
     
            if (!IsPostBack) 
            { 
                //... 
            } 
        } 


    Shinu.
  8. Vinayak
    Vinayak avatar
    12 posts
    Member since:
    Apr 2008

    Posted 07 May 2008 Link to this post

    Hi Princy,

    Thanks for a quick reply.

    These links are quite useful. But in my case it is not showing "+" sign for the records which have child records.

    I am using ItemTemplate columns and I am binding the grid dynamically on the server side. Will it make any difference?

    Regards,
    Vinayak
  9. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 07 May 2008 Link to this post

    Hi Vinayak,

    Are you checking the condition for No ChildItem and hiding the expand button correspondingly?

    CS:
     if (nestedView.Items.Count == 0)  
         {  
          TableCell cell = nestedView.ParentItem["ExpandColumn"];  
          cell.Controls[0].Visible = false;  
          nestedViewItem.Visible = false;  
         } 


    Princy.
  10. Vinayak
    Vinayak avatar
    12 posts
    Member since:
    Apr 2008

    Posted 07 May 2008 Link to this post

    Hi Princy,

    I wrote the show/hide logic in "OnItemDataBound" event. It is working now.

    Sample code:

    protected

    void grdNotices_OnItemDataBound(object sender, Telerik.WebControls.GridItemEventArgs e)
    {
        //IsParent is my project specific property. May be 
        //you have to modify the logic to check if the record has any child records
        if(((ParentObj)e.Item.DataItem).IsParent == false
        {
            TableCell cell = e.Item.Cells[0];
            cell.Controls[0].Visible =
    false;
        }
    }

    Can you provide some direction on how to change header for "ExpandColumn" and how can I move the position of it?

    Thanks a lot to all of you
    Regards,
    Vinayak

  11. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 08 May 2008 Link to this post

    Hi Vinayak,

    Try to hide the Default Expand/Collapse image button and add one GridTemplateColumn at the desired position with Expand/Collapse image button in its ItemTemplate. You can also refer the following code library.
    Custom expand/collapse column with ExpandAll/CollapseAll image button in the header

    Princy.
  12. Vinayak
    Vinayak avatar
    12 posts
    Member since:
    Apr 2008

    Posted 08 May 2008 Link to this post

    Hi Princy,

    Its really great!! This solves my problem. Only thing I could not get is how he is hiding original expand collapse column. 
    On  adding template column for expand collapse, I can see two columns with expand collapse buttons. I have tried to set "visible=false" for ExpandCollapseColumn of Master table but it doesn't work.

    Regards,
    Vinayak
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017