Thanks Manish,
I need autogenerated columns as the GridView may be displaying data from
different sources and have different column properties at different times e.g
column six may be text, and later a checkbox. how can I interrogate the
column properties for an autogenerated column?
guy
> Hi Guy,
>
[quoted text clipped - 19 lines]
> >
> > Guy
Manish - 18 Oct 2007 13:13 GMT
Hi Guy,
Then you can try accessing the RowCreated and RowDataBound event of the
GridView to access the items in any of the columns like below:
Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound
If e.Row.RowType = DataControlRowType.DataRow Then
Response.Write(e.Row.Cells(1).Text)
End If
End Sub
Regards,
Manish
> Thanks Manish,
> I need autogenerated columns as the GridView may be displaying data from
[quoted text clipped - 27 lines]
> > >
> > > Guy
guy - 18 Oct 2007 14:05 GMT
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
---------------------------
> Hi Guy,
>
[quoted text clipped - 42 lines]
> > > >
> > > > Guy
Eliyahu Goldin - 18 Oct 2007 14:05 GMT
You can access the Columns collection for autogenerated columns only in
RowCreated event.

Signature
Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net
> Thanks Manish,
> I need autogenerated columns as the GridView may be displaying data from
[quoted text clipped - 30 lines]
>> >
>> > Guy