I believe the issue is that you need to add the column before you call the databind method on the grid.
Below is some sample code to add a template field and also a datacontrolfield
Add this code to your page and it should add the columns to you grid
Good Luck
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
LoadData()
End Sub
Private Sub LoadData()
Dim pi As New PersonInfo
Dim listOfPI As New List(Of PersonInfo)
pi.Name = "JOEY"
pi.Password = "Password01"
pi.Phone = "555-555-5555"
pi.Gender = "Male"
listOfPI.Add(pi)
pi = New PersonInfo
pi.Name = "Johnny"
pi.Password = "Password02"
pi.Phone = "555-555-6666"
pi.Gender = "Male"
listOfPI.Add(pi)
pi = New PersonInfo
pi.Name = "Jane"
pi.Password = "Password03"
pi.Phone = "555-555-7777"
pi.Gender = "Female"
listOfPI.Add(pi)
pi = New PersonInfo
pi.Name = "Joannie"
pi.Password = "Password03"
pi.Phone = "555-555-8888"
pi.Gender = "Female"
listOfPI.Add(pi)
Dim ngcf As New NewgvColumnField
Dim dcf As DataControlField = ngcf.InsertNewColumn
dcf.HeaderText = "THIS IS THE NEW COLUMN"
dcf.Visible = True
dcf.ShowHeader = True
Me.GridView1.Columns.Insert(2, dcf)
Dim tf As New TemplateField
tf.HeaderText = "TEMPLATE FIELD"
tf.Visible = True
Me.GridView1.Columns.Insert(1, tf)
Me.GridView1.DataSource = listOfPI
Me.GridView1.DataBind()
End Sub
Public Class NewgvColumnField
Inherits DataControlField
Protected Overrides Function CreateField() As System.Web.UI.WebControls.DataControlField
Return New NewgvColumnField
End Function
Public Function InsertNewColumn() As DataControlField
Return CreateField()
End Function
End Class
Private Class PersonInfo
Property Name As String
Property Password As String
Property Phone As String
Property Gender As String
End Class