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

FindControl of InitInsertButton within ItemDataBound event handler

1 Answer 136 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Phil
Top achievements
Rank 2
Phil asked on 11 Feb 2009, 07:48 PM
Hi
I have a RadGrid as follows:
Master (editable)
+ Detail1 (non-editable)
+ Detail2 (insert and editable)

In the MasterView is a status value. The following code works except for the FindControl of InitInsertButton.

Protected Sub invoiceGrid_ItemDataBound(ByVal sender As Object, ByVal e As GridItemEventArgs)  
    If TypeOf e.Item Is GridDataItem Then  
        Dim _item As GridDataItem = e.Item  
        If (_item.OwnerTableView.Name = "InvoiceMasterView") Then  
            ' ... 8 line removed, very similar to following code ...  
        ElseIf (_item.OwnerTableView.Name = "InvoiceDetailAmounts") Then  
            Dim _parentItem As GridDataItem = _item.OwnerTableView.ParentItem  
            Dim _status As Integer = CInt(_parentItem("InvoiceStatus").Text)  
            If Not (Helper.GetStatusUpdatable(_status)) Then  
                Dim _ctl As Control = _item.OwnerTableView.FindControl("InitInsertButton")  
                If Not _ctl Is Nothing Then  
                    CType(_ctl, LinkButton).Enabled = False 
                End If  
                Dim _editCtl As LinkButton = CType(_item("AmountsEditCommandColumn").Controls(0), LinkButton)  
                If Not _editCtl Is Nothing Then  
                    _editCtl.Enabled = False 
                End If  
            End If  
        End If  
    End If  
End Sub  
 

How do I find the InitInsertButton control in the detail2 view in the ItemDataBound event?
Phil

1 Answer, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 2
answered on 12 Feb 2009, 06:52 AM
Hello Phil,

You can try out the following code to disable the InitInsertButton for the level-3 DetailTable of your grid:
cs:
Protected Sub invoiceGrid_ItemDataBound(ByVal sender As Object, ByVal e As GridItemEventArgs) 
    If TypeOf e.Item Is GridDataItem Then 
        Dim _item As GridDataItem = DirectCast(e.Item, GridDataItem) 
         If (_item.OwnerTableView.Name = "InvoiceMasterView") Then 
              ' ... 8 line removed, very similar to following code ... 
         If _item.OwnerTableView.Name = "InvoiceDetailAmounts" Then 
            Dim _parentItem As GridDataItem = _item.OwnerTableView.ParentItem 
            Dim _status As Integer = CInt(_parentItem("InvoiceStatus").Text) 
            If Not (Helper.GetStatusUpdatable(_status) Then 
                Dim _cmdItem As GridCommandItem = DirectCast(_item.OwnerTableView.GetItems(GridItemType.CommandItem)(0), GridCommandItem) 
                Dim _ctl As LinkButton = DirectCast(_cmdItem.FindControl("InitInsertButton"), LinkButton) 
                DirectCast(_ctl, LinkButton).Enabled = False 
                ' To disable the image button 
                Dim btn As Button = DirectCast(_cmdItem.FindControl("AddNewRecordButton"), Button) 
                btn.Enabled = False 
            End If 
        End If 
    End If 
End Sub 

Thanks
Princy.
Tags
Grid
Asked by
Phil
Top achievements
Rank 2
Answers by
Princy
Top achievements
Rank 2
Share this question
or