|
-
Oct 14th, 2004, 08:57 AM
#1
Thread Starter
Fanatic Member
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:
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
-
Oct 14th, 2004, 07:19 PM
#2
PowerPoster
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.
-
Oct 15th, 2004, 03:33 AM
#3
Thread Starter
Fanatic Member
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|