DataGrid_UpdateCommand Not Working

Discussion in 'ASP .Net Web Controls' started by MrMike, Oct 11, 2004.

  1. MrMike

    MrMike Guest

    Hi. I have a datagrid UpdateCommand event that is supposed to identify
    record changes during an edit process and resolve those changes back to a SQL
    database.

    The code below is supposed to identify any changes made to the 16th column
    of the datagrid and update the database. However, when I click the Edit
    hyperlink, make a change to the 16th column, and then click UPDATE the page
    will refresh but no changes are saved. No changes are made and the data is
    back to it's original value.


    ------------------------------------------
    Private Sub DataGrid1_UpdateCommand(ByVal source As Object, _
    ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) _
    Handles DataGrid1.UpdateCommand
    Dim DDL As DropDownList = _
    CType(e.Item.Cells(15).Controls(1), DropDownList)
    Dim NewSpecie As Integer = DDL.SelectedValue
    Dim FlitchNum As String = e.Item.Cells(1).Text
    Dim SQL As String = _
    "UPDATE tblLogs SET SpecieID=@SelectSpecie WHERE FlitchNum=@ID"
    Dim ConnStr As String
    ConnStr = "workstation id=LAPTOP;packet size=4096;integrated
    security=SSPI;data source=sjserver1;persist security info=False;initial
    catalog=dbname"
    Dim Conn As SqlConnection = New SqlConnection(ConnStr)
    Dim Cmd As New SqlCommand(SQL, Conn)
    Cmd.Parameters.Add(New SqlParameter("@SelectSpecie", NewSpecie))
    Cmd.Parameters.Add(New SqlParameter("@ID", FlitchNum))
    Conn.Open()
    Cmd.ExecuteNonQuery()
    Conn.Close()
    DataGrid1.EditItemIndex = -1
    DataGrid1.DataBind()
    ------------------------------------------

    Thanks.
    MrMike, Oct 11, 2004
    #1
    1. Advertising

  2. MrMike

    Jon J. Guest

    Run it in the debugger and see whether you are extracting the changed
    dropdown value correctly. If not, use FindControl to ref the dropdown:

    Dim statusID as String
    Dim DDL as DropDownList = CType(e.Item.FindControl("theDropdownID"),
    DropDownList);

    HTH,

    Jon

    "MrMike" wrote:

    > Hi. I have a datagrid UpdateCommand event that is supposed to identify
    > record changes during an edit process and resolve those changes back to a SQL
    > database.
    >
    > The code below is supposed to identify any changes made to the 16th column
    > of the datagrid and update the database. However, when I click the Edit
    > hyperlink, make a change to the 16th column, and then click UPDATE the page
    > will refresh but no changes are saved. No changes are made and the data is
    > back to it's original value.
    >
    >
    > ------------------------------------------
    > Private Sub DataGrid1_UpdateCommand(ByVal source As Object, _
    > ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) _
    > Handles DataGrid1.UpdateCommand
    > Dim DDL As DropDownList = _
    > CType(e.Item.Cells(15).Controls(1), DropDownList)
    > Dim NewSpecie As Integer = DDL.SelectedValue
    > Dim FlitchNum As String = e.Item.Cells(1).Text
    > Dim SQL As String = _
    > "UPDATE tblLogs SET SpecieID=@SelectSpecie WHERE FlitchNum=@ID"
    > Dim ConnStr As String
    > ConnStr = "workstation id=LAPTOP;packet size=4096;integrated
    > security=SSPI;data source=sjserver1;persist security info=False;initial
    > catalog=dbname"
    > Dim Conn As SqlConnection = New SqlConnection(ConnStr)
    > Dim Cmd As New SqlCommand(SQL, Conn)
    > Cmd.Parameters.Add(New SqlParameter("@SelectSpecie", NewSpecie))
    > Cmd.Parameters.Add(New SqlParameter("@ID", FlitchNum))
    > Conn.Open()
    > Cmd.ExecuteNonQuery()
    > Conn.Close()
    > DataGrid1.EditItemIndex = -1
    > DataGrid1.DataBind()
    > ------------------------------------------
    >
    > Thanks.
    Jon J., Oct 11, 2004
    #2
    1. Advertising

  3. MrMike

    djk Guest

    Hi all,

    I have the same problem. Event is not fired (debugger won't stop at the
    breakpoint) or for some configurations the event is fired, but with wrong
    CommandName text.

    Any help?

    Thanx

    djk



    "Jon J." <.(spamless)> wrote in message
    news:...
    > Run it in the debugger and see whether you are extracting the changed
    > dropdown value correctly. If not, use FindControl to ref the dropdown:
    >
    > Dim statusID as String
    > Dim DDL as DropDownList = CType(e.Item.FindControl("theDropdownID"),
    > DropDownList);
    >
    > HTH,
    >
    > Jon
    >
    > "MrMike" wrote:
    >
    >> Hi. I have a datagrid UpdateCommand event that is supposed to identify
    >> record changes during an edit process and resolve those changes back to a
    >> SQL
    >> database.
    >>
    >> The code below is supposed to identify any changes made to the 16th
    >> column
    >> of the datagrid and update the database. However, when I click the Edit
    >> hyperlink, make a change to the 16th column, and then click UPDATE the
    >> page
    >> will refresh but no changes are saved. No changes are made and the data
    >> is
    >> back to it's original value.
    >>
    >>
    >> ------------------------------------------
    >> Private Sub DataGrid1_UpdateCommand(ByVal source As Object, _
    >> ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) _
    >> Handles DataGrid1.UpdateCommand
    >> Dim DDL As DropDownList = _
    >> CType(e.Item.Cells(15).Controls(1), DropDownList)
    >> Dim NewSpecie As Integer = DDL.SelectedValue
    >> Dim FlitchNum As String = e.Item.Cells(1).Text
    >> Dim SQL As String = _
    >> "UPDATE tblLogs SET SpecieID=@SelectSpecie WHERE FlitchNum=@ID"
    >> Dim ConnStr As String
    >> ConnStr = "workstation id=LAPTOP;packet size=4096;integrated
    >> security=SSPI;data source=sjserver1;persist security info=False;initial
    >> catalog=dbname"
    >> Dim Conn As SqlConnection = New SqlConnection(ConnStr)
    >> Dim Cmd As New SqlCommand(SQL, Conn)
    >> Cmd.Parameters.Add(New SqlParameter("@SelectSpecie", NewSpecie))
    >> Cmd.Parameters.Add(New SqlParameter("@ID", FlitchNum))
    >> Conn.Open()
    >> Cmd.ExecuteNonQuery()
    >> Conn.Close()
    >> DataGrid1.EditItemIndex = -1
    >> DataGrid1.DataBind()
    >> ------------------------------------------
    >>
    >> Thanks.
    djk, Nov 9, 2004
    #3
    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. Ratman
    Replies:
    0
    Views:
    634
    Ratman
    Sep 14, 2004
  2. Martin Heuckeroth
    Replies:
    5
    Views:
    661
    JiangZemin
    Apr 1, 2005
  3. Alan Silver
    Replies:
    1
    Views:
    3,739
    Alan Silver
    Aug 2, 2005
  4. gaurav tyagi
    Replies:
    14
    Views:
    1,301
    gaurav tyagi
    Jan 20, 2006
  5. Priyanka AGARWAL
    Replies:
    9
    Views:
    9,935
    Gordon Beaton
    May 25, 2004
Loading...

Share This Page