title: Unable to cast objects of type 'system.web.ui.webcontrols.imagebutton' to type 'system.web.ui.webcontrols.button'
body: <p>When running <code>gridViewTCOR10.DataBind();</code> It throws an exception:</p>
  
  <pre><code>Unable to cast objects of type system.web.ui.webcontrols.imagebutton 'on the type' system.web.ui.webcontrols.button '.
  </code></pre>
  
  <p>If I use <code>&lt;asp: Button&gt;</code> instead of <code>&lt;asp: ImageButton&gt;</code> it works</p>
  
  <pre><code>private void loadTCOR10()
  {
      try
      {
          SqlDataAdapter adapter = new SqlDataAdapter();
          DataSet ds = new DataSet();
          //int i = 0;
          string sql = null;
          gridViewTCOR10.Visible = true;
          table1.Visible = false;
          string connectionString = SestanteWeb.Global.rCRVigServer.leggiStringaConnessioneSicurezzaSqlClient();
          sql = "select * FROM [PUMA2_FINANZIARIAFAMILIARE].[dbo].[TCOR10]";
          SqlConnection connection = new SqlConnection(connectionString);
          connection.Open();
          SqlCommand command = new SqlCommand(sql, connection);
          adapter.SelectCommand = command;
          adapter.Fill(ds);
          adapter.Dispose();
          command.Dispose();
          connection.Close();
          // gridView1.DataSource = ds.Tables[0];
          gridViewTCOR10.DataSource = ds;
          gridViewTCOR10.DataBind(); //here throw Exception Unable to cast o  bjects of type 
                                     //'system.web.ui.webcontrols.imagebutton' on the type 'system.web.ui.webcontrols.button'.
  
      }
      catch (Exception ex)
      {
  
  
      }
      finally
      {
          //adapter.Dispose();
          //command.Dispose();
          //connection.Close();
  
      }
  }
  
  
  
  en&lt;asp:TemplateField&gt;
                      &lt;EditItemTemplate&gt;
                          &lt;asp:ImageButton ID="ButtonUpdate" runat="server" CommandName="Update" Text="Edit" ImageUrl="~/Images/Cancella.gif" /&gt;
                           &lt;asp:ImageButton ID="ButtonCancel"  runat="server" ImageUrl="~/Images/Cancella.gif" CommandName="Cancel" Text="Delete" /&gt;
                          &lt;%--&lt;asp:Button ID="ButtonUpdate" runat="server" CommandName="Update" Text="Update" /&gt;
                          &lt;asp:Button ID="ButtonCancel" runat="server" CommandName="Cancel" Text="Cancel" /&gt;--%&gt;
                      &lt;/EditItemTemplate&gt;
                      &lt;ItemTemplate&gt;
                           &lt;%--&lt;asp:Button ID="ButtonEdit" runat="server" CommandName="Edit" Text="Edit" /&gt;--%&gt;
  
                           &lt;asp:ImageButton ID="ButtonEdit" runat="server" CommandName="Edit" Text="Edit" ImageUrl="~/Images/Cancella.gif"/&gt;
                           &lt;asp:ImageButton ID="ButtonDelete"  runat="server" ImageUrl="~/Images/Cancella.gif" CommandName="Delete" Text="Delete" /&gt;
  
                          &lt;%--&lt;asp:Button ID="ButtonDelete" runat="server" CommandName="Delete" Text="Delete"  /&gt;--%&gt;
  
                      &lt;/ItemTemplate&gt;
                      &lt;FooterTemplate&gt;
                          &lt;asp:ImageButton ID="ButtonAdd" runat="server" ImageUrl="~/Images/Cancella.gif" CommandName="AddNew" Text="Add New Row" ValidationGroup="validaiton" /&gt;
                          &lt;%--&lt;asp:Button ID="ButtonAdd" runat="server" CommandName="AddNew" Text="Add New Row" ValidationGroup="validaiton" /&gt;--%&gt;
                      &lt;/FooterTemplate&gt;
                  &lt;/asp:TemplateField&gt;
  </code></pre>