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

Hide delete column in second level hiearchy

3 Answers 69 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Aret
Top achievements
Rank 1
Aret asked on 15 Oct 2012, 01:48 AM
I want to loop through a hierarchy radgrid to find a  specific value within the 2nd level of the rad grid's hierarchy.  I do not want the value of the key, but the values of other columns within the 2nd level of the hierarchy.  How can I loop through the items to obtain these values.  This is what I have so far, but it does not work....

   Protected Sub RadGrid_Inventory_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles RadGrid_Inventory.PreRender


            For Each item As GridDataItem In RadGrid_Inventory.Items
                If (item.OwnerTableView.Name = "Inv_Desc") Then


                Dim lblRowID As Label = DirectCast(item.FindControl("lblRowID"), Label)
                Dim Delete As ImageButton = DirectCast(item.FindControl("Delete"), ImageButton)
            

                If lblRowID.Text = -1 Then
                    Delete.Visible = False
                Else
                    Delete.Visible = True
                End If


                End If
            Next
    End Sub

3 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 15 Oct 2012, 04:38 AM
Hi,

Try accessing the delete button as shown below.
VB:
Protected Sub RadGrid2_ItemDataBound(sender As Object, e As GridItemEventArgs)
    If TypeOf e.Item Is GridDataItem AndAlso e.Item.OwnerTableView.Name = "Inv_Desc" Then
        Dim item As GridDataItem = DirectCast(e.Item, GridDataItem)
        Dim lbl As Label = DirectCast(item.FindControl("lblRowID"), Label)
        Dim delete As ImageButton = DirectCast(item("UniqueName").Controls(0), ImageButton)
        If lbl.Text = "-1" Then
            delete.Visible = False
        Else
            delete.Visible = True
        End If
    End If
End Sub

Thanks,
Shinu.
0
Aret
Top achievements
Rank 1
answered on 16 Oct 2012, 01:47 AM
I am getting an error at this line of code:

Dim delete As ImageButton = DirectCast(item("UniqueName").Controls(0), ImageButton)

The error states: Cannot find a cell bound to column name 'Delete'

Is there another alternative...?

0
Aret
Top achievements
Rank 1
answered on 16 Oct 2012, 02:15 AM
I actually just figured out my own solution by doing this:

  Protected Sub RadGrid_Inventory_ItemDataBound(ByVal sender As Object, ByVal e As Telerik.WebControls.GridItemEventArgs) Handles RadGrid_Inventory.ItemDataBound

        For Each item As GridDataItem In RadGrid_Inventory.MasterTableView.Items
            'loops through each materTable rows
            Dim childtableView As GridTableView = DirectCast(item.ChildItem.NestedTableViews(0), GridTableView)
            For Each childItem As GridDataItem In childtableView.Items
                Dim lblRowID As Label = DirectCast(childItem.FindControl("RowID"), Label)
                Dim btnDelete As ImageButton = DirectCast(childItem.FindControl("Delete"), ImageButton)

                If lblRowID.Text = -1 Then
                    btnDelete.Visible = False
                Else
                    btnDelete.Visible = True
                End If
            Next
        Next


    End Sub
Tags
Grid
Asked by
Aret
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Aret
Top achievements
Rank 1
Share this question
or