DataGrid_UpdateCommand Not Working

M

MrMike

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()
 
J

Jon J.

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
 
D

djk

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,266
Messages
2,571,073
Members
48,772
Latest member
Backspace Studios

Latest Threads

Top