UpdateCommand not seeing value

Z

Zach Wells

I've used the datagrid to update data quite extensively without a
problem. However, I've run into a situation where it isn't working and
either I'm missing something terribly obvious or there is some sort of
bug causing it not to work.

I have a 2 column datagrid that I'm loading and binding fine. Delete
works fine. However, when I update (using default edit capabilities, not
using template columns), the control that I get back from the grid is
empty when it should contain the new user entered data. Here is the
relavent code:

Private Sub datagridClients_UpdateCommand(ByVal source As Object,
ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles
datagridClients.UpdateCommand

Dim con As New SqlConnection(Constants.Connection_DB)
Dim cmd As New SqlCommand()

Try
Dim txt As TextBox = CType(e.Item.Cells(1).Controls(0), TextBox)

' at this point, txt.text = "" even though the user
' has entered data into the text box in the datagrid

con.Open()
cmd.Connection = con
cmd.CommandText = "update MyTable " & _
" set Client_Name = '" & txt.Text & "' " & _
" where Client_ID = " & e.Item.Cells(0).Text
cmd.ExecuteNonQuery()

datagridClients.EditItemIndex = -1
LoadData()

Catch ex As Exception
' Error Code here
Finally
If Not cmd Is Nothing Then cmd.Dispose()
If Not con Is Nothing Then
If con.State = ConnectionState.Open Then con.Close()
con.Dispose()
End If
End Try
End Sub

I'm 99.99% sure my code is right (I copied it from a working page). Is
there some event or option that can cause the text box control object
not to pass its value in to the updatecommand event? Are there any other
things I should look at to figure out why my e.Item.Cells(1).Controls(0)
object doesn't have any values?

Zach
 
Z

Zach Wells

Disregard. Looks like an errant </form> tag got stuck in my header
template and was closing the form well before all my controls!

Zach
 

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

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top