Solved

How to get current text in DetailsView BoundField being edited with text box?

Posted on 2008-06-11
4
940 Views
Last Modified: 2008-06-21
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...

Dim plan_num As String = CType(Me.DetailsViewPlan.Rows(0).Cells(1).Controls(0), TextBox).Text

Open in new window

0
Comment
Question by:riceman0
  • 3
4 Comments
 

Author Comment

by:riceman0
ID: 21762353

Okay, tried a slightly different approach which made sense but still didn't work.  Darn, this seemed like the right way!




    Protected Sub LinkButtonSave_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles LinkButtonSave.Click
 

        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 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)
 

' plan_num still equals the wrong value

' dt is a valid data table

' i is the correct number of columns

' x still equals the OLD value (i.e., prior to what the user typed in) of that
 

    End Sub

Open in new window

0
 
LVL 22

Expert Comment

by:prairiedog
ID: 21762427
Is the field you want to validate a BoundField, or a TemplateField?
0
 

Author Comment

by:riceman0
ID: 21762557

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

Open in new window

0
 

Accepted Solution

by:
riceman0 earned 0 total points
ID: 21783962
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

932 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now