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

How to hide value of a column in DetailTables

4 Answers 112 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Amy
Top achievements
Rank 1
Amy asked on 06 Nov 2013, 05:23 PM
Hi,

I've been trying to find an example of hiding a value in a column in a RadGrid detail table.  I've found examples on how to hide an entire column, but that's not what I'm looking for.  I need the column to always be present, and want to hide the value in a row based on the value in that column.  

As a simplified example, let's say I have a numerical column called "ID" in the detail table.  If the value of the "ID" column is 0 then I want to hide that value for that row.  

Here's how I achieved this for the master table in the PreRender event:
'Hide value of SelID if it's 0
            For Each dataItem As GridDataItem In RadGrid1.Items
                For Each col As GridColumn In RadGrid1.Columns
 
                    If col.UniqueName = "sel_id" Then
                        'getting the value of the BoundColumn
                        Dim value As String = dataItem("sel_id").Text
 
                        If value = "0" Then
                            dataItem("sel_id").Text = String.Empty
                        End If
                    End If
                Next
            Next

But I can not seem to figure out how to achieve the same thing in a detail table.  Any assistance would be greatly appreciated.
Thanks!

4 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 07 Nov 2013, 06:49 AM
Hi Amy,

You can identify the DetailTable using its Name property. Please try the following code snippet.

ASPX:
<telerik:GridTableView  Name="Child" . . ./>

VB:
Protected Sub RadGrid1_ItemDataBound(sender As Object, e As GridItemEventArgs)
    If (TypeOf e.Item Is GridDataItem) AndAlso (e.Item.OwnerTableView.Name = "Child") Then
        Dim data As GridDataItem = DirectCast(e.Item, GridDataItem)
        Dim value As String = data("sel_id").Text
        If value = 0 Then
            ' to display respective row of sel_id with Empty String
            data("sel_id").Text = String.Empty
            ' to hide the entire row 
            e.Item.Display = False
 
        End If
    End If
End Sub

Thanks,
Princy
0
Amy
Top achievements
Rank 1
answered on 08 Nov 2013, 04:52 PM
Princy,

Thank you for your assistance!  I've implemented the code you provided; however, the ItemDataBound event doesn't appear to be firing.  I have a break point placed on the initial 'If' statement in Visual Studio, but the break point is never activated. 

I'm performing the data binding for the master and detail tables in the code-behind, could this have an effect?

Thanks again,
Amy
0
Princy
Top achievements
Rank 2
answered on 11 Nov 2013, 05:08 AM
Hi Amy,

Make sure that you have added the OnItemDataBound event to the RadGrid, else the event won't fire.

ASPX:
<telerik:RadGrid ID="RadGrid1" runat="server" OnItemDataBound="RadGrid1_ItemDataBound". . .  >

VB:
Protected Sub RadGrid1_ItemDataBound(sender As Object, e As GridItemEventArgs)
    ' Code Here
End Sub

Thanks,
Princy
0
Amy
Top achievements
Rank 1
answered on 11 Nov 2013, 01:23 PM
Hi Princy,

Thank you that did the trick!  I should've thought about that when the event wasn't firing.  ;)

Thanks again,
Amy
Tags
Grid
Asked by
Amy
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Amy
Top achievements
Rank 1
Share this question
or