Datagrid DataGridCommandEventArgs trouble

Discussion in 'ASP .Net Web Controls' started by Jim Whipkey, Dec 15, 2003.

  1. Jim Whipkey

    Jim Whipkey Guest

    I am using an edit, cancel update button column in a
    datagrid. When a user clicks edit all the columns in the
    row change to textboxes. So far so good.

    The user then changes the contents of one of these boxes
    and clicks update.

    I use the code below to try and capture the new text into
    the tbX.Text property but the OLD text is always
    presented. Can anyone tell me what I'm doing wrong? If I
    look at the Request.Form information I see the NEW text
    but DataGridCommandEventArgs seems to be ignoring the
    change and providing the OLD text.

    Private Sub DataGrid2_UpdateCommand(ByVal source As
    System.Object, ByVal e As
    System.Web.UI.WebControls.DataGridCommandEventArgs)
    Handles DataGrid2.UpdateCommand
    Dim tbX As TextBox = CType(e.Item.Cells(5).Controls
    (0), TextBox)
    DataSet11.ATEducation(e.Item.ItemIndex)("School")
    = tbX.Text
    End Sub

    This is the first time I've tried this so I'm hoping it's
    something simple I've overlooked.

    Thanks for any help you can provide.
    Jim
     
    Jim Whipkey, Dec 15, 2003
    #1
    1. Advertising

  2. Hi Jim,

    I don't see where you call DataBind on the datagrid after you've updated the
    dataset contents e.g.,

    DataGrid2.DataSource = DataSet11
    DataGrid2.DataBind()

    There's some sample code here that might help with the update stuff;

    Is that it? If not, post again?

    http://msdn.microsoft.com/library/d...y/en-us/dnaspp/html/creatingcustomcolumns.asp

    Ken


    "Jim Whipkey" <12.va.us> wrote in message
    news:07ad01c3c31a$1e3b61c0$...
    > I am using an edit, cancel update button column in a
    > datagrid. When a user clicks edit all the columns in the
    > row change to textboxes. So far so good.
    >
    > The user then changes the contents of one of these boxes
    > and clicks update.
    >
    > I use the code below to try and capture the new text into
    > the tbX.Text property but the OLD text is always
    > presented. Can anyone tell me what I'm doing wrong? If I
    > look at the Request.Form information I see the NEW text
    > but DataGridCommandEventArgs seems to be ignoring the
    > change and providing the OLD text.
    >
    > Private Sub DataGrid2_UpdateCommand(ByVal source As
    > System.Object, ByVal e As
    > System.Web.UI.WebControls.DataGridCommandEventArgs)
    > Handles DataGrid2.UpdateCommand
    > Dim tbX As TextBox = CType(e.Item.Cells(5).Controls
    > (0), TextBox)
    > DataSet11.ATEducation(e.Item.ItemIndex)("School")
    > = tbX.Text
    > End Sub
    >
    > This is the first time I've tried this so I'm hoping it's
    > something simple I've overlooked.
    >
    > Thanks for any help you can provide.
    > Jim
     
    Ken Cox [Microsoft MVP], Dec 16, 2003
    #2
    1. Advertising

  3. Hi Jim,

    Thanks for posting in this group.
    Based on my understanding, when you click update button in the "edit,
    cancel update button column", UpdateCommand event fires, but the Dim tbX
    As TextBox = CType(e.Item.Cells(5).Controls(0), TextBox) will get the
    original Text of that editbox.
    I think this is a strange behavior, and I can not reproduce out. In my
    project, I can succeed get the new text value.
    To use "edit, cancel update button column", you should set
    MyDataGrid.EditItemIndex = e.Item.ItemIndex in Edit event.(Also bind the
    grid).
    In Cancel event, you should set MyDataGrid.EditItemIndex = -1, and bind the
    datagrid again.

    The link below shows you a little sample about this:
    http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/
    frlrfsystemwebuiwebcontrolsdatagridclassupdatecommandtopic.asp

    Best regards,
    Jeffrey Tan
    Microsoft Online Partner Support
    Get Secure! - www.microsoft.com/security
    This posting is provided "as is" with no warranties and confers no rights.
     
    Jeffrey Tan[MSFT], Dec 16, 2003
    #3
  4. Jim Whipkey

    Jim Whipkey Guest

    Thanks for your replies Jeff and Ken.

    I found the problem in my Page_Load subroutine. I had the
    following code executing on every load. This re"binded"
    the data to the datagrid, populating the textbox with the
    old value from the database every time before my update
    code had a chance to happen.

    Me.SqlSelectCommand1.Parameters("@UserID").Value = Session
    ("UserID")
    SqlDataAdapter1.Fill(DataSet11.ATExperience)
    DataGrid2.DataSource = DataSet11.ATEducation
    DataGrid2.DataBind()

    I fixed it by doing this

    Me.SqlSelectCommand1.Parameters("@UserID").Value = Session
    ("UserID")
    SqlDataAdapter1.Fill(DataSet11.ATExperience)
    If Not IsPostBack Then
    DataGrid2.DataSource = DataSet11.ATEducation
    DataGrid2.DataBind()
    End If

    which bound the data to the grid on the initial load only
    and then did the bind after performing the updatecommand.

    Thanks again!
     
    Jim Whipkey, Dec 16, 2003
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Hypo
    Replies:
    6
    Views:
    454
  2. Zeljko Krizek
    Replies:
    0
    Views:
    429
    Zeljko Krizek
    Jun 30, 2004
  3. Zeljko Krizek
    Replies:
    0
    Views:
    300
    Zeljko Krizek
    Jun 30, 2004
  4. Andreas Klemt
    Replies:
    0
    Views:
    327
    Andreas Klemt
    Oct 8, 2003
  5. Jim Whipkey

    DataGrid DataGridCommandEventArgs

    Jim Whipkey, Dec 15, 2003, in forum: ASP .Net Web Controls
    Replies:
    1
    Views:
    217
    Jim Whipkey
    Dec 15, 2003
Loading...

Share This Page