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

Disable/Enable Command items when detail table is expanded

11 Answers 180 Views
Grid
This is a migrated thread and some comments may be shown as answers.
zel
Top achievements
Rank 1
zel asked on 30 Sep 2010, 08:54 AM
Hi Everyone,

Is it possible to disable/enable command items of master table when it is expanded? If yes, How?

Attached is the UI for reference.

Thanks!
Zel

11 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 30 Sep 2010, 11:13 AM
Hi,


In the ItemCommand event, check for whether the CommandName is "ExpandCollapseCommandName" and get reference to the parent-table commanditem. Now using FindControl() method, get the buttons and set the Enable property to false.

The help article shows how to access parent item in hierarchy:
http://www.telerik.com/help/aspnet-ajax/grdextractprimarykeyforparentiteminhierarchyonupdateinsert.html


-Shinu.
0
zel
Top achievements
Rank 1
answered on 01 Oct 2010, 04:31 AM
Hi Shinu,

Please check my code below. I always get an error "Object reference not set to an instance of an object." And it will only be triggered if I expanded the detail 2.

if (e.CommandName == RadGrid.ExpandCollapseCommandName)
{
  GridDataItem parentItem = e.Item.OwnerTableView.ParentItem;
  if (parentItem != null)
  {
   if (parentItem.Expanded)
   {
    LinkButton diagbtnAdd = (LinkButton)parentItem.FindControl("master_btnAdd");
    LinkButton diagbtnEditSelected = (LinkButton)parentItem.FindControl("master_btnEditSelected");
    LinkButton diagbtnDelete = (LinkButton)parentItem.FindControl("master_btnDelete");
 
    diagbtnAdd.Enabled = false;
    diagbtnEditSelected.Enabled = false;
    diagbtnDelete.Enabled = false;
   }
  }
}


Thanks!
Zel
0
zel
Top achievements
Rank 1
answered on 01 Oct 2010, 07:46 AM
Hi Shinu,

I have modified the code below. Using this link as reference http://www.telerik.com/help/aspnet/grid/grdusinggetitemsgetcolumnmethods.html

The code is working when clicking the expand/collapse button. First problem is when the user clicks on add or edit then cancel. All disabled command items are enabled. 

Please check my code below.

if (e.CommandName == RadGrid.ExpandCollapseCommandName)
            {
                if (e.Item.OwnerTableView.Name == "Master")
                {
 
                    GridCommandItem commandItem = (GridCommandItem)gridCPDiag.MasterTableView.GetItems(GridItemType.CommandItem)[0];
 
                    LinkButton diagbtnAdd = (LinkButton)commandItem.FindControl("master_btnAdd");
                    LinkButton diagbtnEditSelected = (LinkButton)commandItem.FindControl("master_btnEditSelected");
                    LinkButton diagbtnDelete = (LinkButton)commandItem.FindControl("master_btnDelete");
 
                    if (!e.Item.Expanded)
                    {
                        diagbtnAdd.Enabled = false;
                        diagbtnEditSelected.Enabled = false;
                        diagbtnDelete.Enabled = false;
                    }
                    else {
                        diagbtnAdd.Enabled = true;
                        diagbtnEditSelected.Enabled = true;
                        diagbtnDelete.Enabled = true;
                    }
                     
                }
 
                if (e.Item.OwnerTableView.Name == "Detail2")
                {
                    foreach (GridDataItem masterItem in gridCPDiag.MasterTableView.Items)
                   {
                       if (masterItem.Expanded)
                       {
                           GridCommandItem commandItem = (GridCommandItem)masterItem.ChildItem.NestedTableViews[0].GetItems(GridItemType.CommandItem)[0];
                           LinkButton visitbtnAdd = (LinkButton)commandItem.FindControl("det2_btnAdd");
                           LinkButton visitbtnEditSelected = (LinkButton)commandItem.FindControl("det2_btnEditSelected");
                           LinkButton visitbtnDelete = (LinkButton)commandItem.FindControl("det2_btnDelete");
 
                           visitbtnAdd.Enabled = !visitbtnAdd.Enabled;
                           visitbtnEditSelected.Enabled = !visitbtnEditSelected.Enabled;
                           visitbtnDelete.Enabled = !visitbtnDelete.Enabled;
                       }
                   }
                     
                }
}

Second problem, in detail2, when second row is expanded the command items are enabled. Attached are the sample screenshots for reference.

I would really appreciate for any quick response cause I've been dragging the schedule because of this requirement.

Thanks!
Zel
0
Vasil
Telerik team
answered on 01 Oct 2010, 08:09 AM
Hello zel,

You can define this methood:
public Control FindControlRecursive(Control container, string name)
    {
        if (container.ID == name)
            return container;
  
        foreach (Control ctrl in container.Controls)
        {
            Control foundCtrl = FindControlRecursive(ctrl, name);
            if (foundCtrl != null)
                return foundCtrl;
        }
        return null;
    }

And use it like this:
LinkButton diagbtnAdd = (LinkButton) FindControlRecursive(parentItem.Parent , "master_btnAdd");
To find the link buttons.

Best wishes,
Vasil
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
zel
Top achievements
Rank 1
answered on 01 Oct 2010, 08:16 AM
Thanks for replying Sir. The find control issue is not my problem anymore. I have posted a new problem on how to disable / enable the command items.

Regards,
Zel
0
zel
Top achievements
Rank 1
answered on 04 Oct 2010, 08:26 AM
Hello Support Team,

I really need your help. I am newbie in RAD grid and C#. Please help me with my last problem.

Thanks!
Zel
0
Vasil
Telerik team
answered on 04 Oct 2010, 10:27 AM
Hello zel,

I wrote a simple site based on your code. After clicking Add, and then cancel the editing, the disabled LinkButtons remains disabled. Check the attachment for further details.

All the best,
Vasil
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
zel
Top achievements
Rank 1
answered on 05 Oct 2010, 03:12 AM
Hi Sir,

I don't see any difference, the sample website you sent is still not working on the required functionality. Can you discuss what you have added in the code?

Thanks!
Zel

0
zel
Top achievements
Rank 1
answered on 05 Oct 2010, 08:13 AM
Hi Sir,

I got a solution in my first problem. I have saved the state of expanded item into session and get the value of session in item databound event.

My second problem, is in detail2, when first row is expanded the command items are disabled, but when second row is expanded the command items are enabled.

How to check if any detail row gets expanded? 

Please check my code below, maybe there is something that I missed. The code will only work when user expand the first row then collapse, expand the second row then collapse. Just to note, that I added a code to allow only one row to expand. For example, when first row is expanded then the user expanded the second row, the first row will automatically collapsed.
if (e.Item.OwnerTableView.Name == "Detail2")
                {
                    foreach (GridDataItem masterItem in gridCPDiag.MasterTableView.Items)
                    {
                        if (masterItem.Expanded)
                        {
                            GridCommandItem commandItem = (GridCommandItem)masterItem.ChildItem.NestedTableViews[0].GetItems(GridItemType.CommandItem)[0];
                            LinkButton visitbtnAdd = (LinkButton)commandItem.FindControl("det2_btnAdd");
                            LinkButton visitbtnEditSelected = (LinkButton)commandItem.FindControl("det2_btnEditSelected");
                            LinkButton visitbtnDelete = (LinkButton)commandItem.FindControl("det2_btnDelete");
 
                            visitbtnAdd.Enabled = !visitbtnAdd.Enabled;
                            visitbtnEditSelected.Enabled = !visitbtnAdd.Enabled;
                            visitbtnDelete.Enabled = !visitbtnAdd.Enabled;
                        }
                    }
                }

I hope I can get an answer as soon as possible. I would really appreciate for any assistance.

Thanks!
Zel
0
Accepted
Vasil
Telerik team
answered on 05 Oct 2010, 01:15 PM
Hi zel,

Instead of
visitbtnAdd.Enabled = !visitbtnAdd.Enabled;
you can use this code:
int countOfExpandedItems = 0;
foreach (GridItem item in e.Item.OwnerTableView.Items)
{
    if (item.Expanded)
    {
        countOfExpandedItems += 1;
    }
}
visitbtnAdd.Enabled = (e.Item.Expanded && countOfExpandedItems == 1);


Best wishes,
Vasil
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
zel
Top achievements
Rank 1
answered on 06 Oct 2010, 03:22 AM
Hi Sir,

Thank you! The code is working. :D

Regards,
Zel
Tags
Grid
Asked by
zel
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
zel
Top achievements
Rank 1
Vasil
Telerik team
Share this question
or