I have a problem where the EditItemIndex is being reset to -1 after editing but it still shows in the updating mode and will not go back to the regular mode after Update is clicked.<BR><BR><BR>Sub choiceInsert(ByVal sender As Object, ByVal e As DataGridCommandEventArgs)<BR> Response.Write("In Insert <BR>")<BR> ProdID = htmlHiddenProdID.Value<BR> Dim OptionID As Integer<BR> If CheckBoxList1.SelectedIndex &#062; -1 Then<BR> OptionID = CInt(CheckBoxList1.SelectedItem.Value)<BR> htmlHiddenOpID.Value = OptionID<BR> Else<BR> OptionID = htmlHiddenOpID.Value<BR> End If<BR><BR> lblCatNotice.Visible = False<BR> lblNotice.Visible = False<BR> lblCrossSell.Visible = False<BR> Dim txtChoice, txtCode As TextBox<BR> Dim Choice, Code As String<BR><BR> If e.CommandName = "Insert" Or e.CommandName = "Update" Then<BR> Dim strSQL As String<BR> If e.CommandName = "Insert" Then<BR> txtChoice = e.Item.FindControl("txtAddChoice")<BR> txtCode = e.Item.FindControl("txtAddCode")<BR> Else<BR> txtChoice = e.Item.Cells(0).Controls(1)<BR> txtCode = e.Item.Cells(1).Controls(1)<BR> End If<BR><BR> If e.CommandName = "Insert" Then<BR> strSQL = "INSERT INTO OptionDetails (DetailID, Choice, @ItemCode)" & _<BR> " VALUES (@DetailID, @Choice, @ItemCode)"<BR> Else<BR> strSQL = _<BR> "UPDATE OptionDetails SET OptionID = @OptionID, " & _<BR> "Choice = @Choice, ItemCode = @ItemCode " & _<BR> "WHERE DetailID = @DetailID"<BR> End If<BR><BR> Dim cmdExp As SqlCommand<BR> oConn = New SqlConnection(SQL_CONNECTION_STRING)<BR> cmdExp = New SqlCommand(strSQL, oConn)<BR><BR> With cmdExp.Parameters<BR> &#039; The PriceID parameter is only needed for updating.<BR> If e.CommandName = "Update" Then<BR> .Add(New SqlParameter("@OptionID", _<BR> SqlDbType.Int)).Value = CInt(OptionID)<BR> End If<BR> .Add(New SqlParameter("@Choice", _<BR> SqlDbType.VarChar)).Value = txtChoice.Text<BR> .Add(New SqlParameter("@ItemCode", _<BR> SqlDbType.VarChar)).Value = txtCode.Text<BR> .Add(New SqlParameter("@DetailID", _<BR> SqlDbType.Int)).Value = CInt(grdChoice.DataKeys(e.Item.ItemIndex).ToString )<BR> End With<BR><BR> Try<BR> oConn.Open()<BR> cmdExp.ExecuteNonQuery()<BR> Catch exp As Exception<BR> lblAddChoice.Visible = True<BR> If e.CommandName = "Insert" Then<BR> lblAddChoice.Text = " Database error! Choice not added." & _<BR> " Error message: " & exp.Message<BR> Else<BR> lblAddChoice.Text = " Database error! Choice not updated." & _<BR> " Error message: " & exp.Message<BR> End If<BR> Finally<BR> oConn.Close()<BR> End Try<BR> grdChoice.EditItemIndex = -1<BR> End If<BR>End Sub