How to find a control in a DetailTables CommandItemTemplate

1 Answer 47 Views
Grid
SSirica
Top achievements
Rank 2
Iron
Iron
Veteran
SSirica asked on 24 Jun 2022, 03:03 PM

I have a grid.  It has a MasterTableView and a DetailTables with a GridTableView that has a CommandItemTemplate.  In the DetailTableDataBind event I need to hide a button when certain conditions apply.  I can't for the life of me figure out how to access these buttons.  I can get to the buttons in the MasterTableView's CommandItemTemplate, but not the Detail Table. 

Anyone know how to access these little buggers?  VB.NET if at all possible...please and thank you.  if you need for me to post my grid structure I can.  

1 Answer, 1 is accepted

Sort by
0
Accepted
Attila Antal
Telerik team
answered on 29 Jun 2022, 01:30 PM

Hello Steve,

I suggest that you use the ItemDataBound event of the Grid. There is almost no other event as efficient and optimal for such operation than this.

 

This event will trigger every item in the Grid. Be that the CommandItem of the MasterTable or CommandItem of the DetailTable. The easiest way you can understand where this item comes from is if you name the GridTableViews on every Level.

<telerik:RadGrid ID="RadGrid2" runat="server" OnItemDataBound="RadGrid2_ItemDataBound">
    <MasterTableView Name="MasterTable">
        <DetailTables>
            <telerik:GridTableView Name="ChildTable">
                <DetailTables>
                    <telerik:GridTableView Name="GrandChildTable"></telerik:GridTableView>
                    </DetailTables>
            </telerik:GridTableView>
        </DetailTables>
    </MasterTableView>
</telerik:RadGrid>

 

In the ItemDataBound event you can differentiate the Items coming from different DetailTables if you knew the name.

protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
{
    if (e.Item is GridCommandItem)
    {
        GridCommandItem commandItem = (GridCommandItem)e.Item;

        string tableName = e.Item.OwnerTableView.Name;

        if (tableName == "MasterTable")
        {
            // Item of the Master Table
        }
        else if (tableName == "ChildTable")
        {
            // Item of the Child Table
        }
        else if (tableName == "GrandChildTable")
        {
            // Item of the Grand Child Table
        }
    }
}

 

If you want to access the Item from another event, (e.g. Button click) you can loop through the DetailTables like explained in the Traversing detail tables/items in Telerik RadGrid.

 

Once you found the Detail table, you can access the Controls using the approach from the Accessing Values and Controls article.

 

I hope this will be helpful.

 

Regards,
Attila Antal
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Tags
Grid
Asked by
SSirica
Top achievements
Rank 2
Iron
Iron
Veteran
Answers by
Attila Antal
Telerik team
Share this question
or