riceman0
asked on
How to get current text in DetailsView BoundField being edited with text box?
Hi, I have a manual (i.e., bound to my own DataTable, not an actual data source like a database) DetailsView (with DefaultMode = Edit) on my ASP.NET web form, and I have set up several fields in it. So elsewhere I have a link button, and when I push it I want to
1) check the data for validity
2) save it to the actual database
3) navigate to a different page
Well, it seems like I can't get the current text typed into a text box, the code below seems to return what was *initially* in the DetailsView (or my "bound" DataTable).
Thanks very much.
How can I get the current text typed into the text box when the user clicks my LinkButton? Is there some sort of Update method that shoots the DetailsView back to my DataTable? Thanks...
1) check the data for validity
2) save it to the actual database
3) navigate to a different page
Well, it seems like I can't get the current text typed into a text box, the code below seems to return what was *initially* in the DetailsView (or my "bound" DataTable).
Thanks very much.
How can I get the current text typed into the text box when the user clicks my LinkButton? Is there some sort of Update method that shoots the DetailsView back to my DataTable? Thanks...
Dim plan_num As String = CType(Me.DetailsViewPlan.Rows(0).Cells(1).Controls(0), TextBox).Text
Is the field you want to validate a BoundField, or a TemplateField?
ASKER
I believe it is a bound field.
Your question got me excited because yes, why am I accessing the textbox control instead of the cell value itself. Unfortunately the code below (added the two assignments to "plan_num2") didn't work either, accessing the cell value returns blank strings. Grr.
Protected Sub LinkButtonSave_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles LinkButtonSave.Click
Dim plan_num2 As String = Me.DetailsViewPlan.Rows(0).Cells(1).Text ' returns BLANK string, not typed data
Me.DetailsViewPlan.UpdateItem(True)
End Sub
Protected Sub DetailsViewPlan_ItemUpdating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DetailsViewUpdateEventArgs) Handles DetailsViewPlan.ItemUpdating
Dim plan_num As String = CType(Me.DetailsViewPlan.Rows(0).Cells(1).Controls(0), TextBox).Text
Dim plan_num2 As String = Me.DetailsViewPlan.Rows(0).Cells(1).Text ' returns BLANK string, not typed info
Dim dt As Data.DataTable = CType(DetailsViewPlan.DataSource, Data.DataTable)
Dim i As Integer = dt.Columns.Count
Dim x As String = dt.Rows(0).Item(0)
End Sub
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Okay, tried a slightly different approach which made sense but still didn't work. Darn, this seemed like the right way!
Open in new window