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

Using ItemCommand to rebind a hierarchy RADGrid

2 Answers 143 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Darrell
Top achievements
Rank 1
Darrell asked on 03 Mar 2009, 07:36 PM
We have a 4 layer hierarchy RADGrid (1 - MasterTableView and 3 GridTableViews).  On each layer there are 4 asp:LinkButtons(Divisions, Sites, Accounts, and Fiscal Year).  We want to expand or collapse the RADGrid by clicking on either the ExpandCollapseColumn or the asp:LinkButton.  For example we want the user to be able to click (or double-click) on the Division (or the <ExpandCollapseColumn>) and they would see the Sites GridTableView.  If they click it again it should collapse the Sites.  We currently handle the OnDetailTableDataBind,  OnItemCommand,  OnItemCreated, and OnNeedDataSource events. Can you provide some assistance on how to do this? It was suggested that this could be done by using Client-Side DataBinding but the example shows how to expand the first MasterTableView and first GridTableView only.

I have included the codel-behind (Visual Basic 2.0)

Protected Sub

rgCUBudget_DetailTableDataBind(ByVal source As Object, ByVal e As Telerik.Web.UI.GridDetailTableDataBindEventArgs)

 

 

 

    Dim

dataItem As Telerik.Web.UI.GridDataItem = CType(e.DetailTableView.ParentItem, Telerik.Web.UI.GridDataItem)

 

 

 

    Select Case

e.DetailTableView.Name

 

 

        Case "AccountDetail"

 

             

tbBudget = LoadObject(tbBudget)

 

             

tbBudget.AccountId = dataItem.GetDataKeyValue("account_id").ToString()

 

             

e.DetailTableView.DataSource = tbBudget.LoadBudgetAccountDetail()

 

 

 

        Case

"AccountSummary"

 

             

tbBudget = LoadObject(tbBudget)

 

             

tbBudget.SiteId = dataItem.GetDataKeyValue("site_id").ToString()

 

             

e.DetailTableView.DataSource = tbBudget.LoadBudgetAccountSummary()

 

 
        Case

"SiteSummary"

 

             

tbBudget = LoadObject(tbBudget)

 

             

tbBudget.DivisionId = dataItem.GetDataKeyValue("division_id").ToString()

 

 

            e.DetailTableView.DataSource = tbBudget.LoadBudgetSiteSummary()

 

     End Select

 

End Sub

 

 

Protected Sub

rgCUBudget_ItemCommand(ByVal source As Object, ByVal e As Telerik.Web.UI.GridCommandEventArgs)

 

     If

e.CommandName = "loadSites" Then

 

         For Each 

item As GridDataItem In rgCUBudget.Items

 

 

             If item.OwnerTableView.Name = "DivisionSummary" Then

 

                 

tbBudget = LoadObject(tbBudget)

 

                 

tbBudget.DivisionId = CType(item, GridDataItem).GetDataKeyValue("division_id").ToString()

 

             End If

        Next

    End If

 

End Sub

 

 


Protected Sub

rgCUBudgetDetail_DetailTableDataBind(ByVal source As Object, ByVal e As Telerik.Web.UI.GridDetailTableDataBindEventArgs)

 

     Dim

dataItem As Telerik.Web.UI.GridDataItem = CType(e.DetailTableView.ParentItem, Telerik.Web.UI.GridDataItem)

 

 
     Select Case

e.DetailTableView.Name

 

         

Case "AccountDetail2"

 

             

tbBudget = LoadObject(tbBudget)

 

             

tbBudget.AccountId = dataItem.GetDataKeyValue("account_id").ToString()

 

             

e.DetailTableView.DataSource = tbBudget.LoadBudgetAccountDetail()

 

         
         Case

"AccountSummary2"

 

 

             tbBudget = LoadObject(tbBudget)

 

             

tbBudget.SiteId = dataItem.GetDataKeyValue("site_id").ToString()

 

             

e.DetailTableView.DataSource = tbBudget.LoadBudgetAccountSummary()

 

 

 

         Case

"SiteSummary2"

 

 

            tbBudget = LoadObject(tbBudget)

 

 

            tbBudget.DivisionId = dataItem.GetDataKeyValue("division_id").ToString()

 

 

            e.DetailTableView.DataSource = tbBudget.LoadBudgetSiteSummary()

 

     End Select

 

End Sub

 

 


2 Answers, 1 is accepted

Sort by
0
Iana Tsolova
Telerik team
answered on 06 Mar 2009, 01:24 PM
Hello Darrell,

You could handle the items expanding on ItemCommand event. For that purpose you need to set the CommandName property of the LinkButton. You code should be like the below snippet:

<asp:LinkButton ID="LinkButton1" runat="server" CommandName="Division">Division</asp:LinkButton> 
Protected Sub RadGrid1_ItemCommand(sender As Object, e As GridCommandEventArgs)  
    If e.CommandName = "Division" Then 
        (TryCast(e.Item, GridDataItem)).Expanded = True 
    End If 
End Sub 

Check it out and let me know if this works for you.

Kind regards,
Iana
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Darrell
Top achievements
Rank 1
answered on 06 Mar 2009, 01:42 PM
Thank lyou for your help.  Using the "Expanded" property, we were able to get this working.

Thank You
Tags
Grid
Asked by
Darrell
Top achievements
Rank 1
Answers by
Iana Tsolova
Telerik team
Darrell
Top achievements
Rank 1
Share this question
or