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

Hide Columns in Grid

3 Answers 101 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Andrew
Top achievements
Rank 1
Andrew asked on 22 Apr 2011, 09:55 AM
I want to hide a couple of columns in a grid. At the moment the grid is set to autogenerate columns. Can I hide the columns somehow and also resize the columns.

Thanks

Andrew

3 Answers, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 22 Apr 2011, 01:39 PM
Hello Andrew,

The easiest way would be to use the ColumnCreated event:
protected void RadGrid1_ColumnCreated(object sender, Telerik.Web.UI.GridColumnCreatedEventArgs e)
{
  if(e.Column.UniqueName == "MyColumnName")
  {
      ...
  }
}

I would recommend that you examine the following help topic:
Using Columns

Let me know if you need further assistance.

Best regards,
Daniel
the Telerik team

Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

0
Andrew
Top achievements
Rank 1
answered on 22 Apr 2011, 02:55 PM
Thanks that link would be helpful

Where would this code be put:

Protected Sub RadGrid1_ColumnCreated(sender As Object, _
     e As Telerik.Web.UI.GridColumnCreatedEventArgs) _
     Handles RadGrid1.ColumnCreated
  If e.Column.UniqueName = "BirthDate" Then
    Dim boundColumn As GridBoundColumn = CType(e.Column, GridBoundColumn)
    boundColumn.ReadOnly = True
    boundColumn.DataFormatString = "{0:d}"
    End If
End Sub 'RadGrid1_ColumnCreated

Does this go on the page_load. I am using vb and code behind
0
Daniel
Telerik team
answered on 25 Apr 2011, 09:22 AM
Hello Andrew,

ColumnCreated is an event and as such it should not be placed in another event.
Public Partial Class Default3VB
    Inherits System.Web.UI.Page
 
    Protected Sub RadGrid1_ColumnCreated(ByVal sender As Object, _
     ByVal e As Telerik.Web.UI.GridColumnCreatedEventArgs) _
     Handles RadGrid1.ColumnCreated
        If e.Column.UniqueName = "BirthDate" Then
            Dim boundColumn As GridBoundColumn = CType(e.Column, GridBoundColumn)
            boundColumn.ReadOnly = True
            boundColumn.DataFormatString = "{0:d}"
        End If
    End Sub 'RadGrid1_ColumnCreated
    ...

Regards,
Daniel
the Telerik team

Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

Tags
Grid
Asked by
Andrew
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Andrew
Top achievements
Rank 1
Share this question
or