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

Remove plus sign for expanding detail table if unnecessary

10 Answers 495 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Vinayak
Top achievements
Rank 1
Vinayak asked on 05 May 2008, 11:10 AM
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

10 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 05 May 2008, 12:43 PM
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.
0
Puneet
Top achievements
Rank 1
answered on 06 May 2008, 02:38 AM
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.  
0
Kiara
Top achievements
Rank 1
answered on 06 May 2008, 11:14 AM
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
0
Puneet
Top achievements
Rank 1
answered on 06 May 2008, 08:17 PM
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.   
0
Shinu
Top achievements
Rank 2
answered on 07 May 2008, 10:42 AM
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.
0
Vinayak
Top achievements
Rank 1
answered on 07 May 2008, 10:49 AM
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
0
Princy
Top achievements
Rank 2
answered on 07 May 2008, 12:02 PM
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.
0
Vinayak
Top achievements
Rank 1
answered on 07 May 2008, 12:52 PM
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

0
Princy
Top achievements
Rank 2
answered on 08 May 2008, 05:41 AM
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.
0
Vinayak
Top achievements
Rank 1
answered on 08 May 2008, 12:47 PM
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
Tags
Grid
Asked by
Vinayak
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Puneet
Top achievements
Rank 1
Kiara
Top achievements
Rank 1
Shinu
Top achievements
Rank 2
Vinayak
Top achievements
Rank 1
Share this question
or