Datagrid EditItemTemplate not passing Updated Value

Posted on 2004-11-30
Last Modified: 2008-02-26
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

Question by:shorriga
    1 Comment
    LVL 1

    Accepted Solution

    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.


    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    Suggested Solutions

    Introduction Many web sites contain image galleries; a common design for these galleries includes a page with a collection of thumbnail images.  You can click on each of the thumbnail images to see the larger version of the image.  This is easily i…
    Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
    Viewers will get an overview of the benefits and risks of using Bitcoin to accept payments. What Bitcoin is: Legality: Risks: Benefits: Which businesses are best suited?: Other things you should know: How to get started:
    This tutorial walks through the best practices in adding a local business to Google Maps including how to properly search for duplicates, marker placement, and inputing business details. Login to your Google Account, then search for "Google Mapmaker…

    734 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    21 Experts available now in Live!

    Get 1:1 Help Now