UpdateCommand not seeing value

Discussion in 'ASP .Net Datagrid Control' started by Zach Wells, Apr 15, 2004.

  1. Zach Wells

    Zach Wells Guest

    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
    Zach Wells, Apr 15, 2004
    #1
    1. Advertising

  2. Zach Wells

    Zach Wells Guest

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

    Zach
    Zach Wells, Apr 15, 2004
    #2
    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. richard

    get DataField value in UpdateCommand

    richard, Dec 2, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    406
    richard
    Dec 2, 2003
  2. logan
    Replies:
    0
    Views:
    541
    logan
    Jun 28, 2005
  3. =?Utf-8?B?Y2xpY2tvbg==?=
    Replies:
    0
    Views:
    353
    =?Utf-8?B?Y2xpY2tvbg==?=
    Apr 5, 2006
  4. srathin

    DataGrid1 UpdateCommand calling DataGrid2 UpdateCommand

    srathin, Apr 9, 2005, in forum: ASP .Net Datagrid Control
    Replies:
    0
    Views:
    174
    srathin
    Apr 9, 2005
  5. srathin

    DataGrid1 UpdateCommand calling DataGrid2 UpdateCommand

    srathin, Apr 9, 2005, in forum: ASP .Net Web Controls
    Replies:
    2
    Views:
    158
    srathin
    Apr 11, 2005
Loading...

Share This Page