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

Hide GridTemplateColumn

5 Answers 248 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Chase Florell
Top achievements
Rank 1
Chase Florell asked on 10 Nov 2008, 03:12 AM
I have a GridTemplateColumn that can only be visible to specific roles within my system.  My problems is that I cannot figure out to hide it... any help would be great.
    Protected Sub RadGrid1_ColumnCreated(ByVal sender As ObjectByVal e As Telerik.Web.UI.GridColumnCreatedEventArgs) Handles RadGrid1.ColumnCreated  
        If e.Column.UniqueName = "Edit" Then e.Column.Visible = False 
 
    End Sub 'RadGrid1_ColumnCreated 

5 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 10 Nov 2008, 04:39 AM
Hi,

Try hiding the Template column in the Grid PreRender event as shown below.

CS:
 
 
     Protected Sub RadGrid1_PreRender(ByVal sender As Object, ByVal e As EventArgs) 
         For Each col As GridColumn In RadGrid1.MasterTableView.RenderColumns 
             If (col.ColumnType & "GridTemplateColumn") AndAlso (col.UniqueName & "Edit") Then 
                 col.Display = False 
             End If 
         Next 
         
     End Sub 
 
 


Thanks
Shinu.
0
Chase Florell
Top achievements
Rank 1
answered on 10 Nov 2008, 05:43 AM
Sorry no dice.  If I use that code straight up I get error : 'GridTemplateColumn' is a type and cannot be used as an expression
If I remove (col.ColumnType = GridTemplateColumn) AndAlso

The column still appears in the form.
0
Chase Florell
Top achievements
Rank 1
answered on 10 Nov 2008, 04:04 PM
Have you any other suggestions?
0
Accepted
Bob
Top achievements
Rank 1
answered on 10 Nov 2008, 07:00 PM
Chase, you pretty much had it right in the initial sample you posted.

 

If TypeOf e.Column Is GridBoundColumn Then  
If e.Column.UniqueName = "Edit" Then e.Column.Visible = False    
End If   
 

 

 

Ought to do it for you.

I'm actually working on the same type of stuff right now.
My entire code is:

    Sub gridEvil_ColumnCreated(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridColumnCreatedEventArgs) Handles gridEvil.ColumnCreated  
        If TypeOf e.Column Is GridBoundColumn Then  
            Dim col As GridBoundColumn = DirectCast(e.Column, GridBoundColumn)  
            If col.UniqueName = "MealPeriodID" Then  
                col.Visible = False 
            End If  
        End If  
    End Sub 


Yes, called mine gridEvil.  It's gonna be......  :-(

 

 

 

0
Chase Florell
Top achievements
Rank 1
answered on 10 Nov 2008, 07:35 PM
Awesome thanks, This seems to have done it for me.
    Protected Sub RadGrid1_PreRender(ByVal sender As ObjectByVal e As System.EventArgs) Handles RadGrid1.PreRender  
        For Each col As GridColumn In RadGrid1.MasterTableView.RenderColumns  
            If col.UniqueName = "Edit" Then 
                If (Page.User.IsInRole("Business Trader Advanced")) Or (Page.User.IsInRole("Business Trader Administrator")) Then 
                    col.Display = True 
                Else 
                    col.Display = False 
                End If 
            End If 
        Next 
    End Sub 
Tags
Grid
Asked by
Chase Florell
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Chase Florell
Top achievements
Rank 1
Bob
Top achievements
Rank 1
Share this question
or