title: Programmatically Add ButtonColumn to GridView From DataTable
body: <p>I have a problem adding a column with buttons in GridView.</p>
  
  <p>As you see from the code below, the data source from teh GridView is a DataTable. I need to add an additional column to the table with a button. </p>
  
  <p>From the code below, I get an error message saying:</p>
  
  <blockquote>
    <p>Value of type 'System.Windows.Forms.DataGridViewButtonColumn' cannot
    be converted to 'System.Web.UI.WebControls.DataControlField'.</p>
  </blockquote>
  
  <pre><code>    Dim dt_AllGroupsSetUp2 As New DataTable()
      dt_AllGroupsSetUp2.Columns.Add("Name", Type.GetType("System.String"))
      dt_AllGroupsSetUp2.Columns.Add("Age", Type.GetType("System.String"))
      dt_AllGroupsSetUp2.Columns.Add("Hight", Type.GetType("System.String"))
  
      For i As Integer = 0 To 7
          dt_AllGroupsSetUp2.Rows.Add()
          dt_AllGroupsSetUp2.Rows(i)(0) = "John"
          dt_AllGroupsSetUp2.Rows(i)(1) = 10
          dt_AllGroupsSetUp2.Rows(i)(2) = 70
      Next
  
      GV_DataByGroupAct.DataSource = dt_AllGroupsSetUp2
      Dim buttonColumn As New DataGridViewButtonColumn
      buttonColumn.Name = "Button"
      GV_DataByGroupAct.Columns.Add(buttonColumn)
      GV_DataByGroupAct.DataBind()
  </code></pre>
  
  <p>I tried the folling also but returned the following error: 'New' cannot be used on a class that is declared 'MustInherit'.</p>
  
  <pre><code>    GV_DataByGroupAct.DataSource = dt_AllGroupsSetUp2
      Dim buttonColumn As New DataControlField
      GV_DataByGroupAct.Columns.Add(buttonColumn)
      GV_DataByGroupAct.DataBind()
  </code></pre>
  
  <p>Any ideas?</p>
  
  <p>Thanks</p>