Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1272
  • Last Modified:

How to Get DropDownList Control Value from FormView ItemUpdated Event

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?
Thanks.
MCallas
0
MCallas
Asked:
MCallas
  • 3
  • 3
1 Solution
 
Jared_SCommented:
I'm sorry for asking, but is that the actual code you're using? Do you have a key named EmployeeID?
0
 
MCallasAuthor Commented:
Jared_S,
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()
            Else
                ' 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

Thanks.
Michael
0
 
MCallasAuthor Commented:
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!
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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

ctype(fvDocuments.FindControl("myDDListID"),DropDownList).SelectedValue.ToString()
0
 
Jared_SCommented:
That's much prettier than mine.. nice!
0
 
MCallasAuthor Commented:
I found this solution on the Internet and it worked.
0

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now