How to Get DropDownList Control Value from FormView ItemUpdated Event

Posted on 2012-09-14
Last Modified: 2012-09-19
Dear Experts,
How do I get the data from a DropDownList control in the FormView.ItemUpdated event section? I have tried using MS's suggestion of

Dim keyFieldValue As String = e.Keys("EmployeeID").ToString()

When testing this on a textbox control for simplicity, the line above keeps throwing a NullReferenceException was unhandled by user code error even though the field has a value.

What am I missing here?
Question by:MCallas
    LVL 12

    Expert Comment

    I'm sorry for asking, but is that the actual code you're using? Do you have a key named EmployeeID?

    Author Comment

    No worries. Here's my code:

       Protected Sub fvDocuments_ItemUpdated(sender As Object, e As System.Web.UI.WebControls.FormViewUpdatedEventArgs) Handles fvDocuments.ItemUpdated

            If e.Exception Is Nothing Then
                If e.AffectedRows = 1 Then
                    ' Use the Keys property to get the value of the key field.
                    Dim keyFieldValue As String = e.Keys("txtDCDocNbr").ToString()
                    ' Display an error message.
                    MessageLabel.Text = "An error occurred during the update operation."
                    ' When an error occurs, keep the FormView
                    ' control in edit mode.
                    e.KeepInEditMode = True
                End If
            End If
        End Sub


    Accepted Solution

    I solved this particular issue. Because I am using a DataSource, I can use the Name in the UpdateParameters section in my code. This is how I got it to work:

    Dim sOldValue As String = e.OldValues("DCDocStatusID").ToString()                
    Dim sNewValue As String = e.NewValues("DCDocStatusID").ToString()

    Worked like a charm!
    LVL 12

    Expert Comment

    Maybe I'm over-complicating this,  but give this a shot.

    LVL 12

    Expert Comment

    That's much prettier than mine.. nice!

    Author Closing Comment

    I found this solution on the Internet and it worked.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    For most people, the WrapPanel seems like a magic when they switch from WinForms to WPF. Most of us will think that the code that is used to write a control like that would be difficult. However, most of the work is done by the WPF engine, and the W…
    A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
    This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA.…
    This video discusses moving either the default database or any database to a new volume.

    755 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

    20 Experts available now in Live!

    Get 1:1 Help Now