Results 1 to 3 of 3

Thread: problems retrieving text from textbox on datagrid when edit/update

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Oct 1999
    Location
    England
    Posts
    982

    problems retrieving text from textbox on datagrid when edit/update

    I have a datagird with the edit feature enabled.
    When the update command is fired the text property of the textbox in the datagrid column is empty though there is text there.
    I have included the EditCommand and UpdateCommand subs for you to see.
    In UpdateCommand strText is always = ""

    Please Help
    VB Code:
    1. Private Sub dgrSelected_EditCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles dgrSelected.EditCommand
    2.  
    3.         dgrSelected.EditItemIndex = e.Item.ItemIndex
    4.         dgrSelected.DataSource = m_dvwData
    5.         dgrSelected.DataBind()
    6.     End Sub
    7.  
    8.     Private Sub dgrSelected_UpdateCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles dgrSelected.UpdateCommand
    9.  
    10.         Dim strText As String
    11.         Dim txtText As New TextBox  '= CType(e.Item.Cells(4).Controls(0), TextBox)
    12.         txttext = CType(e.Item.Cells(4).Controls(0), TextBox)
    13.         strText = txtText.Text
    14.  
    15.         dgrSelected.EditItemIndex = -1
    16.         dgrSelected.DataSource = m_dvwData
    17.         dgrSelected.DataBind()
    18.     End Sub


    Things I do when I am bored: DotNetable

  2. #2
    PowerPoster hellswraith's Avatar
    Join Date
    Jul 2002
    Location
    Washington St.
    Posts
    2,464
    I have found that sometimes a literalcontrol is at index 0, and the textbox is at index one. The better way would be something like this though:

    txttext = CType(e.Item.Cells(4).FindControl("YourTextBoxName"))
    or
    txttext = CType(e.Item.Cells(4).Controls.FindControl("YourTextBoxName"))

    Not sure on the exact syntax there, but I think it is one of those. This will have the added effect of not needing to worry if the indexes ever change, so long as the name never changes.

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Oct 1999
    Location
    England
    Posts
    982
    I don't know the name of the textbox because it is in a boundcolumn that changes into a textbox when the EditCommand event fires.


    Things I do when I am bored: DotNetable

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width