title: How to resolve the "Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index" error message?
body: <p>I made a list of employees connected to MySQL database. Every employee's name can do CRUD. However, when updating employee data, this error message appears "Index was out of range. Must be non-negative and less than the size of the collection. Parameter name : index" </p>
  
  <p>How to overcome it? Here is my code</p>
  
  <pre><code>try {
    if (e.CommandName.Equals("Tambah")) {
      using(SqlConnection sqlcon = new SqlConnection(connectionString)) {
        sqlcon.Open();
        string query = "INSERT INTO EmployeeDB (NamaLengkap,Alamat,Telp,Email,Gender,Jabatan) VALUES (@NamaLengkap,@Alamat,@Telp,@Email,@Gender,@Jabatan)";
        SqlCommand sqlcmd = new SqlCommand(query, sqlcon);
        sqlcmd.Parameters.AddWithValue("@NamaLengkap", (gvEmployeeDB.FooterRow.FindControl("txtNamaLengkapFooter") as TextBox).Text.Trim());
        sqlcmd.Parameters.AddWithValue("@Alamat", (gvEmployeeDB.FooterRow.FindControl("txtAlamatFooter") as TextBox).Text.Trim());
        sqlcmd.Parameters.AddWithValue("@Telp", (gvEmployeeDB.FooterRow.FindControl("txtTelpFooter") as TextBox).Text.Trim());
        sqlcmd.Parameters.AddWithValue("@Email", (gvEmployeeDB.FooterRow.FindControl("txtEmailFooter") as TextBox).Text.Trim());
        sqlcmd.Parameters.AddWithValue("@Gender", (gvEmployeeDB.FooterRow.FindControl("txtGenderFooter") as TextBox).Text.Trim());
        sqlcmd.Parameters.AddWithValue("@Jabatan", (gvEmployeeDB.FooterRow.FindControl("txtJabatanFooter") as TextBox).Text.Trim());
        sqlcmd.ExecuteNonQuery();
        PopulateGridView();
        lblSuccessMessage.Text = "New Record Add!";
        lblErrorMessage.Text = "";
      }
    }
  } catch (Exception ex) {
  
    lblSuccessMessage.Text = "";
    lblErrorMessage.Text = ex.Message;
  }
  </code></pre>