locked
Update function not work in Gridview when add code in rowdatabound RRS feed

  • Question

  • User954010692 posted

    Hi There,

    I add some code in the rowdatabound in Gridview. Then the data can not be update. If I remove them, then the update functiom works fine. Why?

    Here is my code:

        Protected Sub GridView2_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView2.RowDataBound
            If e.Row.RowType = DataControlRowType.DataRow Then

               If e.Row.RowState = DataControlRowState.Edit Or e.Row.RowState = 5 Then

                    CType(e.Row.FindControl("txtEMPL"), TextBox).Text = Session("User_ID")
                    CType(e.Row.FindControl("txtDATE"), TextBox).Text = Today

                End If

            End If

        End Sub

     

    I try to set the txtEMPL default value as employe ID. and txtDATE as today when I going to edit a line.

    If I remove the code, the txtEMPL show up as empty. I can type any data (ex:1111) and save it. The Gridview show 1111 without any problem.

    If I add the code, the txtEMPL show up with the data (ex: ID0001). But when I click "update", nothing change in the database.

    WHY? Thanks for you help~~

     

    Wednesday, October 30, 2013 11:13 PM

Answers

  • User-1454326058 posted

    Hi Brian,

    Thanks for your post!

    I suggest that you could set the breakpoint then debug the update method check the data and the code.

    If you still have the issue, please provide the detail code about update event and the GridView.

    Thanks

    Best Regards

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, November 1, 2013 5:21 AM

All replies

  • User-1454326058 posted

    Hi Brian,

    Thanks for your post!

    I suggest that you could set the breakpoint then debug the update method check the data and the code.

    If you still have the issue, please provide the detail code about update event and the GridView.

    Thanks

    Best Regards

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, November 1, 2013 5:21 AM
  • User954010692 posted

    When u set a field as  read only , then the update will not work in edit mode. I don;t know why.

    But after change to "Disable" in stead of "Read only", then update functiom can work normally.

    FYR  

    Sunday, November 10, 2013 7:59 PM
  • User-1426144113 posted

    Hi,

    When u set a field as  read only , then the update will not work in edit mode

    When you set the field as read only or disable, why you can type value in it?

    Thanks

    Monday, November 11, 2013 8:31 PM