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


Help with retreiving ID value from Dropdownlist

Posted on 2011-10-12
Medium Priority
Last Modified: 2012-08-14

I am loading my Dropdownlist (CmbRec) using code A, buyt when I use code B and try to use ReceiverID of the first row displayed, with the following code.

I receive the following error:

But I am able to retrieve DonorID from Dropdownlist1, can’t figure out why it’s working for Dropdownlist1 and not for CmbRec. Can you please help me figure out why I can’t extract the ReceiverID value from CmbRec.
Code A:
Dim xdDonor As New Xml.XmlDocument
        Dim xdLink As New Xml.XmlDocument
        Dim xdReceiver As New Xml.XmlDocument

        ' load all of the XML documents

        ' This outer loop will iterate over the Link file where the ReceiverID node is equal to our search criteria
        For Each xnLink As Xml.XmlNode In xdLink.SelectNodes("/Root/Link[ReceiverID='" & C1Country.SelectedItem.Value & "']")

            ' Extract the ReceiverID and DonorID values from the current node
            Dim ReceiverID As String
            Dim DonorID As String

            ReceiverID = xnLink.SelectSingleNode("ReceiverID").InnerText
            DonorID = xnLink.SelectSingleNode("DonorID").InnerText

            ' Perform another similar search based upon the Donor XML file
            For Each xnDonor As Xml.XmlNode In xdDonor.SelectNodes("/Root/Donor[DonorID='" & DonorID & "']")

                ' Extract the DonorID and Name values from the current node
                Dim DonorID2 As String
                Dim Name As String

                DonorID2 = xnDonor.SelectSingleNode("DonorID").InnerText
                Name = xnDonor.SelectSingleNode("Name").InnerText
                dtDonor.Rows.Add({DonorID2, Name})

            ' Perform yet another practically identical search on the Receiver XML file
            For Each xnReceiver As Xml.XmlNode In xdReceiver.SelectNodes("/Root/Receiver[ReceiverID='" & ReceiverID & "']")
                ' Extract the ReceiverID and Name values from the current node
                Dim ReceiverID2 As String
                Dim Name As String

                ReceiverID2 = xnReceiver.SelectSingleNode("ReceiverID").InnerText
                Name = xnReceiver.SelectSingleNode("Name").InnerText
                dtReceiver.Rows.Add({ReceiverID2, Name})


        CmbRec.DataSource = dtReceiver
        CmbRec.DataTextField = "Name"
        CmbRec.DataValueField = "ReceiverID"

        DropDownList1.DataSource = dtDonor
        DropDownList1.DataTextField = "Name"
        DropDownList1.DataValueField = "DonorID"

Code B:
Dim an As String
        an = MsgBox("Are you sure you want to Delete this record?", MsgBoxStyle.YesNo, "Warning before Attempting to Save Data")
        MsgBox(CmbRec.SelectedItem.Value) *****Error
        If an = MsgBoxResult.Yes Then
            Dim xml As String = LinkStream.InnerXml
            Dim newline As String = Environment.NewLine
            Dim replacement As String = "<Link><ReceiverID>" & CmbRec.SelectedItem.Value & "</ReceiverID><DonorID>" & DropDownList1.SelectedItem.Value & "</DonorID></Link>"
            LinkStream.InnerXml = xml.Replace(replacement, "")
            Dim cnt As Integer = LinkStream.SelectNodes("Root/Link").Count
            MsgBox("Record was deleted")
        End If
        If an = MsgBoxResult.No Then
            MsgBox("Record was not deleted")
        End If
    End Sub
Question by:vcharles
  • 4
  • 2
LVL 83

Accepted Solution

CodeCruiser earned 2000 total points
ID: 36954353
Place a breakpoint somewhere and examine all the SelectedIndex, SelectedItem, SelectedValue etc properties of both DDLs and see what's coming up.

Also, are you adding columns to dtDonor and dtReceiver anywhere?

Author Comment

ID: 36954362
Ok, I will try it. No I'm not adding any columns.

Author Comment

ID: 36954472
Strange outcome:
When I include:
In codeA, they both return the ID values, than when I include the same thing at the beginning of CodeB:
CmbRec returns a Blank value, but DropDownList1 returns the same DonorID that was returned in the mesaagebox in Code A.
Any ideas why CmbRec is not returning ReceiverID in Code B?

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!

LVL 83

Expert Comment

ID: 36959164
> No I'm not adding any columns.
How does the dropdown then know which column is Name and which one is ReceiverID when you use the code

CmbRec.DataSource = dtReceiver
        CmbRec.DataTextField = "Name"
        CmbRec.DataValueField = "ReceiverID"


Author Comment

ID: 36968275
I am using:

            dtReceiver = New DataTable
            dtReceiver.Columns.Add("ReceiverID", GetType(String))
            dtReceiver.Columns.Add("Name", GetType(String))
            dtDonor = New DataTable
            dtDonor.Columns.Add("DonorID", GetType(String))
            dtDonor.Columns.Add("Name", GetType(String))

I was able to fix the bug.



Author Closing Comment

ID: 36968279
Thank You!

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

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

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…

571 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