Thanks Manish, I have knocked up class to give more control I know changes
that I ned to make but it works
cheers
Guy
------------------------
Option Strict On
Imports Microsoft.VisualBasic
Public Class AutoGridColumns
Private _fieldCells As New List(Of DataControlFieldCell)
Private _view As GridView
Public Property FieldCells() As List(Of DataControlFieldCell)
Get
Return _fieldCells
End Get
Set(ByVal value As List(Of DataControlFieldCell))
_fieldCells = value
End Set
End Property
Public Sub New(ByVal view As GridView)
Refresh(view)
End Sub
Public Sub Refresh(ByVal view As GridView)
_view = view
If _view.Rows.Count > 0 Then
For Each cell As DataControlFieldCell In _view.Rows(0).Controls
FieldCells.Add(cell)
Next
End If
End Sub
Public Sub HideColumn(ByVal columnNo As Integer)
FieldCells(columnNo).Visible = False
For Each r As GridViewRow In _view.Rows
r.Controls(columnNo).Visible = FieldCells(columnNo).Visible
Next
_view.HeaderRow.Controls(columnNo).Visible =
FieldCells(columnNo).Visible
End Sub
Public Sub ShowColumn(ByVal columnNo As Integer)
FieldCells(columnNo).Visible = False
For Each r As GridViewRow In _view.Rows
r.Controls(columnNo).Visible = FieldCells(columnNo).Visible
Next
_view.HeaderRow.Controls(columnNo).Visible =
FieldCells(columnNo).Visible
End Sub
End Class
---------------------------