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

RadGrid PreRender

1 Answer 753 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Kent
Top achievements
Rank 1
Kent asked on 02 Mar 2011, 10:14 PM
Im having some trouble understanding why I cant access columns within the PreRender function.  Here is the code.  I am loading the grid at runtime.

Why do I not get inside of either of these loops?  But, the commented code will set the ID columns visibility to false if uncommented.
Private Sub RadGrid_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles RadGrid.PreRender
    For Each column As GridColumn In RadGrid.MasterTableView.Columns
        If column.UniqueName = "ID" Then
            column.Visible = False 'Not column.Visible
        End If
    Next
    For Each column2 As GridColumn In RadGrid.Columns
        If column2.UniqueName = "ID" Then
            column2.Visible = False 'Not column.Visible
        End If
    Next
    'Dim column3 As GridColumn = RadGrid.MasterTableView.GetColumnSafe("ID")
    'If column3 IsNot Nothing Then
    '    column3.Visible = False 'Not column.Visible
    'End If
    RadGrid.MasterTableView.Rebind()
End Sub

Here is the PageLoad just in case.
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    If Not IsPostBack() Then
        Dim bp As BasePage
        bp = CType(Parent.Page, BasePage)
        RadGrid.DataSource = bp.mDs
        bp.ExecuteQuery(" WHERE 1 = 0 ")
    End If
End Sub

1 Answer, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 03 Mar 2011, 06:01 AM
Hello Kent,

Try the following code snippet and see if it works.

Vb.Net:
Protected Sub RadGrid_PreRender(sender As Object, e As EventArgs)
    For Each column As GridColumn In RadGrid.MasterTableView.AutoGeneratedColumns
        If column.UniqueName = "ID" Then
            column.Visible = False
        End If
    Next
End Sub

Or you can try the same in ColumnCreated event since the columns are AutoGeneratedColumns.

Protected Sub RadGrid_ColumnCreated(sender As Object, e As GridColumnCreatedEventArgs)
    If e.Column.UniqueName = "ID" Then
        e.Column.Visible = False
    End If
End Sub

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