PDA

Click to See Complete Forum and Search --> : problems retrieving text from textbox on datagrid when edit/update


davidrobin
Oct 14th, 2004, 08:57 AM
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
Private Sub dgrSelected_EditCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles dgrSelected.EditCommand

dgrSelected.EditItemIndex = e.Item.ItemIndex
dgrSelected.DataSource = m_dvwData
dgrSelected.DataBind()
End Sub

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

Dim strText As String
Dim txtText As New TextBox '= CType(e.Item.Cells(4).Controls(0), TextBox)
txttext = CType(e.Item.Cells(4).Controls(0), TextBox)
strText = txtText.Text

dgrSelected.EditItemIndex = -1
dgrSelected.DataSource = m_dvwData
dgrSelected.DataBind()
End Sub

hellswraith
Oct 14th, 2004, 07:19 PM
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.

davidrobin
Oct 15th, 2004, 03:33 AM
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.