Datagrid EditItemTemplate not passing Updated Value

I have a datagrid edititemtemplate column (ordinal value [2]) with a textbox called “txtEditItemDeptName”. When I go to update the record, “txtEditItemDeptName” is always equal to the old value.

For example in the datagrid I have a row called “test”. I hit edit and the textbox comes up, and I type in “test 2”. The value that is getting passed behind the scenes is “test”, not “test 2”.

I have just added some sorting and paging functions which I think have affected this somehow. Any ideas?

 Private Sub dgDeptMaint_UpdateCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles dgDeptMaint.UpdateCommand
        Dim strDeptNum As String
        Dim strDeptNameUpdate As String

        'Attach datagrid edit items to the variables.
        strDeptNum = CType(e.Item.FindControl("lblDeptNo_EditItem"), Label).Text
        ****----->strDeptNameUpdate = CType(e.Item.Cells(2).FindControl("txtEditItemDeptName"), TextBox).Text
        strSQLQuery = "UPDATE JJORA.TBLBNK_Dept SET BNK_Dept_NM = " & myHelper.DoubleUpQuotes(strDeptNameUpdate) & " " & _
                      " WHERE BNK_Dept_NO = " & myHelper.DoubleUpQuotes(strDeptNum)

        lblStatus.CssClass() = "DARKBLUETEXT"
        lblStatus.Text = "You just updated Dept: " & strDeptNameUpdate

        'Set to jump out of Edit Mode
        dgDeptMaint.EditItemIndex = -1


    End Sub

    Private Sub ps_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Me.dgDeptMaint.CurrentPageIndex = 0
    End Sub

    Private Sub dgDeptMaint_PageIndexChanged(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridPageChangedEventArgs) Handles dgDeptMaint.PageIndexChanged
        dgDeptMaint.CurrentPageIndex = e.NewPageIndex
    End Sub

    Private Sub dgDeptMaint_SortCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridSortCommandEventArgs) Handles dgDeptMaint.SortCommand

            If viewstate("sortdirection") = "ASC" Then
                viewstate("sortdirection") = "DESC"
                viewstate("sortdirection") = "ASC"
            End If

    End Sub

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Its possible that something in your page load is reloading the values, are the initial values being loaded on Page_Load? if so ensure they are in an if not page.ispostback block.


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Development

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.