Link to home
Start Free TrialLog in
Avatar of Victor  Charles
Victor CharlesFlag for United States of America

asked on

Help with If statement to filter data in Link.xml file

Hello,

I'm trying to display data in two combo boxes based on values entered in a textbox. The trick is donor.xm; and Receiver.xml are linked to Link.xml by ReceiverID and DonorID.  Below is an example of all three xml files.

For example, when I seach for ReceiverID = 3 in my Textbox, CmbRec  should have value: CCCR
and if multiple records are found, I need to move to the next record using the Next/Previous buttons.

However I'm not getting the correct value, I'm getting a value of 1

Can you please take a look at my If statement to see what I'm doing wrong..

Thanks,

Victor

Link.xml:
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<Root>
  <Link>
    <ReceiverID>1</ReceiverID>
    <DonorID>2</DonorID>
  </Link>
  <Link>
    <ReceiverID>3</ReceiverID>
    <DonorID>3</DonorID>
  </Link>
</Root>

Receiver.xml
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<Root>
  <Receiver>
    <ReceiverID>1</ReceiverID>
    <Name>AAAA</Name>
  </Receiver>
  <Receiver>
    <ReceiverID>2</ReceiverID>
    <Name>BBBB</Name>
  </Receiver>
  <Receiver>
    <ReceiverID>3</ReceiverID>
    <Name>CCCR</Name>
  </Receiver>
</Root>

Donor.xml

<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<Root>
  <Donor>
    <DonorID>1</DonorID>
    <Name>AAA</Name>
  </Donor>
  <Donor>
    <DonorID>2</DonorID>
    <Name>BBBB</Name>
  </Donor>
  <Donor>
    <DonorID>3</DonorID>
    <Name>CCCD</Name>
  </Donor>
</Root>

Code:

DonorStream.Load(Server.MapPath("~/App_Data/Donor.xml")) 'My.Resources.Donor)
        RecStream.Load(Server.MapPath("~/App_Data/Receiver.xml")) 'My.Resources.Receiver)
        LinkStream.Load(Server.MapPath("~/App_Data/Link.xml")) 'My.Resources.Link)


        Dim lnk As XmlNodeList = LinkStream.SelectNodes("Root/Link")
        Dim RecName As XmlNodeList = RecStream.SelectNodes("Root/Receiver")
        Dim DonorName As XmlNodeList = DonorStream.SelectNodes("Root/Donor")

        'Create Table
        Dim donorlst As New DataTable()
        donorlst.Columns.Add("ID")
        donorlst.Columns.Add("Name")

        Dim reclst As New DataTable
        reclst.Columns.Add("ID")
        reclst.Columns.Add("Name")

        'Load Link.xml
        Dim MyLink As XDocument = XDocument.Load(Server.MapPath("~/App_Data/Link.xml"))

        'Create varaible CheckForItem to see if I being searched exit in Link.xml
        Dim CheckForItem = (From el In MyLink.Descendants("Link").Elements("ReceiverID") Select el.Value).ToList

        'Loop Through all records in Link.xml and assign first childnode the rID and second childnode to dID
        For Each n As XmlNode In lnk
            If CheckForItem.Contains(Me.TextBox2.Text.ToString) Then
                Dim rID As Integer = Val(n.ChildNodes(0).InnerText)
                Dim dID As Integer = Val(n.ChildNodes(1).InnerText)

                'Loop Through all records in Receiver.xml and if ReceiverID = Textbox2.text and if the firstnode
                For Each node As XmlNode In RecName

                    If node.ChildNodes(0).InnerText = rID.ToString Then
                        reclst.Rows.Add(New Object() {rID, node.ChildNodes(1).InnerText})
                    End If

                Next

            For Each node As XmlNode In DonorName
                If node.ChildNodes(0).InnerText = dID.ToString Then
                    donorlst.Rows.Add(New Object() {node.ChildNodes(0).InnerText, node.ChildNodes(1).InnerText})
                    'donorlst.Rows.Add(New Object() {dID, node.ChildNodes(1).InnerText})
                End If
                Next
            End If
        Next

        CmbDonor.DataSource = donorlst
        CmbDonor.DataTextField = "Name"
        CmbDonor.DataValueField = "ID"
        CmbDonor.DataBind()

        CmbRec.DataSource = reclst
        CmbRec.DataTextField = "Name"
        CmbRec.DataValueField = "ID"
        CmbRec.DataBind()
Avatar of graye
graye
Flag of United States of America image

The problem is with the LINQ query at
            If CheckForItem.Contains(Me.TextBox2.Text.ToString) Then

... this would always show true for every node even if it only matched one node.

I'd suggest that you abandon the LINQ technique and go back to good 'ole XPath query to find the nodes that match the item from the comboboxes

http://support.microsoft.com/kb/317069
Avatar of Victor  Charles

ASKER

Can I use both XPath and Linq in thje same project? I looked at your link but still can not figure out how to get it to work withe two xml files linked to my link.xml file, can you please help me with the code.

Thanks,

victor
By the way, I only receive records when I enter a ReceiverID that exit in Link.xml, if I enter the wrong ID no records are returned, so it seems to me that the application understands " If CheckForItem.Contains(Me.TextBox2.Text.ToString)" If you want I can send you the project.
Sure, you can use both... I was just trying to simply the problem for you...

If you're more comfortable using LINQ rather than XPath, that's OK.  But you'll have to tweak that LINQ query to only look for the search item in the current "link" node (not all of the "link" nodes).
Can you please send me a sample code on how you would achieve the same using XPATH.
Thanks.
OK... here is what I'm talking about.   Note: This was typed by hand, so watch for typos...

This XPath query will find all "link" nodes that that have an RecieverID equal to your search critera.   You could use this same technique to speed up the other searches as well, since an XPath query is almost always better than manualy looping through the XML hunting for matching items (that's what XPath is for!).

Yeah, I  know... XPath is a strange beast, but it's worth learning.  There are a gazillion resources on the web to help speed you along.
'Loop Through all records in Link.xml and assign first childnode the rID and second childnode to dID
        For Each n As XmlNode In MyLink.SelectNodes("/root/link[RecieverID=" & Me.TextBox2.Text & "]")
                Dim rID As Integer = Val(n.ChildNodes(0).InnerText)
                Dim dID As Integer = Val(n.ChildNodes(1).InnerText)

                'Loop Through all records in Receiver.xml and if ReceiverID = Textbox2.text and if the firstnode
                For Each node As XmlNode In RecName

                    If node.ChildNodes(0).InnerText = rID.ToString Then
                        reclst.Rows.Add(New Object() {rID, node.ChildNodes(1).InnerText})
                    End If

                Next

            For Each node As XmlNode In DonorName
                If node.ChildNodes(0).InnerText = dID.ToString Then
                    donorlst.Rows.Add(New Object() {node.ChildNodes(0).InnerText, node.ChildNodes(1).InnerText})
                    'donorlst.Rows.Add(New Object() {dID, node.ChildNodes(1).InnerText})
                End If
            Next
        Next

Open in new window

Thanks a million. I will try it and get back to you.
Hi,

I tried your code, but I'm getting error:
SelectNodes is not a member of System.Xml.Linq.XDocument
On line:
 For Each n As XmlNode In MyLink.SelectNodes("/root/link[RecieverID=" & Me.TextBox2.Text & "]")

Code:

 Protected Sub Button9_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button9.Click
        DonorStream.Load(Server.MapPath("~/App_Data/Donor.xml")) 'My.Resources.Donor)
        RecStream.Load(Server.MapPath("~/App_Data/Receiver.xml")) 'My.Resources.Receiver)
        LinkStream.Load(Server.MapPath("~/App_Data/Link.xml")) 'My.Resources.Link)


        Dim lnk As XmlNodeList = LinkStream.SelectNodes("Root/Link")
        Dim RecName As XmlNodeList = RecStream.SelectNodes("Root/Receiver")
        Dim DonorName As XmlNodeList = DonorStream.SelectNodes("Root/Donor")

        'Create Table
        Dim donorlst As New DataTable()
        donorlst.Columns.Add("ID")
        donorlst.Columns.Add("Name")

        Dim reclst As New DataTable
        reclst.Columns.Add("ID")
        reclst.Columns.Add("Name")

        'Load Link.xml
        Dim MyLink As XDocument = XDocument.Load(Server.MapPath("~/App_Data/Link.xml"))
        'Loop Through all records in Link.xml and assign first childnode the rID and second childnode to dID
        For Each n As XmlNode In MyLink.SelectNodes("/root/link[RecieverID=" & Me.TextBox2.Text & "]")
            Dim rID As Integer = Val(n.ChildNodes(0).InnerText)
            Dim dID As Integer = Val(n.ChildNodes(1).InnerText)

            'Loop Through all records in Receiver.xml and if ReceiverID = Textbox2.text and if the firstnode
            For Each node As XmlNode In RecName

                If node.ChildNodes(0).InnerText = rID.ToString Then
                    reclst.Rows.Add(New Object() {rID, node.ChildNodes(1).InnerText})
                End If

            Next

            For Each node As XmlNode In DonorName
                If node.ChildNodes(0).InnerText = dID.ToString Then
                    donorlst.Rows.Add(New Object() {node.ChildNodes(0).InnerText, node.ChildNodes(1).InnerText})
                    'donorlst.Rows.Add(New Object() {dID, node.ChildNodes(1).InnerText})
                End If
            Next
        Next
    End Sub
Sorry, how about  

LinkStream.SelectNodes
I imported  Imports System.Xml.XPath and tried XPath in the code below but it's still not working.

 'Load Link.xml
        Dim MyLink As Xml.XPath.XPathDocument = XPathDocument.Load(Server.MapPath("~/App_Data/Link.xml"))
        'Loop Through all records in Link.xml and assign first childnode the rID and second childnode to dID
        For Each n As XmlNode In MyLink.SelectNodes("/root/link[RecieverID=" & Me.TextBox2.Text & "]")
            Dim rID As Integer = Val(n.ChildNodes(0).InnerText)
            Dim dID As Integer = Val(n.ChildNodes(1).InnerText)
Hello,

I modified the code but it still doesn't filter the Link file based on the value entered in the Textbox, can you please take a look at my code to see what I'm doing wrong.

 Protected Sub Search_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Search.Click
        DonorStream.Load(Server.MapPath("~/App_Data/Donor.xml")) 'My.Resources.Donor)
        RecStream.Load(Server.MapPath("~/App_Data/Receiver.xml")) 'My.Resources.Receiver)
        LinkStream.Load(Server.MapPath("~/App_Data/Link.xml")) 'My.Resources.Link)


        Dim lnk As XmlNodeList = LinkStream.SelectNodes("Root/Link")
        Dim RecName As XmlNodeList = RecStream.SelectNodes("Root/Receiver")
        Dim DonorName As XmlNodeList = DonorStream.SelectNodes("Root/Donor")

        'Create Table
        Dim donorlst As New DataTable()
        donorlst.Columns.Add("ID")
        donorlst.Columns.Add("Name")

        Dim reclst As New DataTable
        reclst.Columns.Add("ID")
        reclst.Columns.Add("Name")

        'Load Link.xml
        Dim MyLink As XDocument = XDocument.Load(Server.MapPath("~/App_Data/Link.xml"))
        'Loop Through all records in Link.xml and assign first childnode the rID and second childnode to dID
        For Each n As XmlNode In LinkStream.SelectNodes("/root/link[RecieverID=" & Me.TextBox2.Text & "]")
            Dim rID As Integer = Val(n.ChildNodes(0).InnerText)
            Dim dID As Integer = Val(n.ChildNodes(1).InnerText)

            'Loop Through all records in Receiver.xml and if ReceiverID = Textbox2.text and if the firstnode
            For Each node As XmlNode In RecName

                If node.ChildNodes(0).InnerText = rID.ToString Then
                    reclst.Rows.Add(New Object() {rID, node.ChildNodes(1).InnerText})
                End If

            Next

            For Each node As XmlNode In DonorName
                If node.ChildNodes(0).InnerText = dID.ToString Then
                    donorlst.Rows.Add(New Object() {node.ChildNodes(0).InnerText, node.ChildNodes(1).InnerText})
                    'donorlst.Rows.Add(New Object() {dID, node.ChildNodes(1).InnerText})
                End If
            Next
        Next
    End Sub

Thanks,

Victor
Hello,

Below is the link to the project.

http://www.speedyshare.com/files/30631341/AmendProject.zip

For example when I enter 2 in my Textbox, The comboboxes should display the first record where ReceiverID = 2 in Link.xml and if more than 1 record exist they should be viewed by clicking on the Next Button.

Can you please take a look at the project to help me solve this issue..

Thanks

Victor
Hello,

I'm trying to use Xpath but it's not working with some of existind variables (i.e Dim rID As Integer = Val(n.ChildNodes(0).InnerText)), can you please help me figure out how to integrate the Xpath command with my existing code: I hard coded the value of the Textbox on the code below, but it doesn't undertsand when I use Textbox2.text.

        Dim iterator As System.Xml.XPath.XPathNodeIterator = nav.Select("//ReceiverID[. = Textbox2.Text]/parent::node()/Link")



Code:
 Dim DonorStream As New System.Xml.XPath.XPathDocument(Server.MapPath("~/App_Data/Donor.xml"))
        Dim RecStream As New System.Xml.XPath.XPathDocument(Server.MapPath("~/App_Data/Receiver.xml"))
        Dim LinkStream As New System.Xml.XPath.XPathDocument(Server.MapPath("~/App_Data/Link.xml"))
 ''Create Table
        Dim donorlst As New DataTable()
        donorlst.Columns.Add("ID")
        donorlst.Columns.Add("Name")

        Dim reclst As New DataTable
        reclst.Columns.Add("ID")
        reclst.Columns.Add("Name")
        '' MsgBox(TextBox2.Text)
        ''Load Link.xml
        ' Dim MyLink As XDocument = XDocument.Load(Server.MapPath("~/App_Data/Link.xml"))
        Dim nav As System.Xml.XPath.XPathNavigator = LinkStream.CreateNavigator()
        ''Loop Through all records in Link.xml and assign first childnode the rID and second childnode to dID
        Dim iterator As System.Xml.XPath.XPathNodeIterator = nav.Select("//ReceiverID[. = '1']/parent::node()/Link")
        Do While iterator.MoveNext
            ' For Each n As XmlNode In LinkStream.SelectNodes("/root/link[ReceiverID=" & Me.TextBox2.Text & "]")
            Dim rID As Integer = Val(n.ChildNodes(0).InnerText)
            Dim dID As Integer = Val(n.ChildNodes(1).InnerText)

            ' 'Loop Through all records inn  Receiver.xml and if ReceiverID = Textbox2.text and if the firstnode
            For Each node As XmlNode In RecName

                If node.ChildNodes(0).InnerText = rID.ToString Then
                    reclst.Rows.Add(New Object() {rID, node.ChildNodes(0).InnerText})
                End If

            Next

            For Each node As XmlNode In DonorName
                If node.ChildNodes(0).InnerText = dID.ToString Then
                    donorlst.Rows.Add(New Object() {dID, node.ChildNodes(1).InnerText})
                    ''donorlst.Rows.Add(New Object() {dID, node.ChildNodes(1).InnerText})
                End If
            Next
        Loop
    End Sub


Thanks,

Victor
I'll work on it later today...
I'm looking froward to hear back from you,

Thanks for your efforts.

Victor
OK here is a complete and working example... with some comments and debug output so you can see what's going on.

It's not a complete "drop in" replacement, since I didn't setup a web page...
' create a new XML Document object for each XML file
        Dim xdDonor As New Xml.XmlDocument
        Dim xdLink As New Xml.XmlDocument
        Dim xdReceiver As New Xml.XmlDocument

        ' load all of the XML documents
        xdDonor.Load("Donor.xml")
        xdLink.Load("Link.xml")
        xdReceiver.Load("Receiver.xml")

        ' I'm faking the text box here...
        Dim TextBoxText As String = "1"

        ' 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='" & TextBoxText & "']")
            ' 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

            Debug.WriteLine("From Link.xml...")
            Debug.WriteLine("ReceiverID=" & ReceiverID)
            Debug.WriteLine("DonorID=" & DonorID)

            ' 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

                Debug.WriteLine("From Donor.xml...")
                Debug.WriteLine("DonorID=" & DonorID2)
                Debug.WriteLine("Name=" & Name)
            Next

            ' Perform yet another practically identical search on the Receiver XML file
            For Each xnReceiver As Xml.XmlNode In xdDonor.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

                Debug.WriteLine("From Reciever.xml...")
                Debug.WriteLine("ReceiverID=" & ReceiverID2)
                Debug.WriteLine("Name=" & Name)
            Next
        Next

Open in new window

See?  XPath is not so bad...   I use it along with LINQ.   So, I'd encourage you to learn both techniques...
Yikes!  I found a typo...

For Each xnReceiver As Xml.XmlNode In xdReceiver.SelectNodes("/Root/Receiver[ReceiverID='" & ReceiverID & "']")
                                                           ^^^^^^^
I don't know what's wrong, my comboboxes are blank and my message box statements are not executing, only first message box with HHHH appears, can you please send me the xml files you are using, perhaps we have different format, as I've been modifying them to try to solve the problem. Thanks.

Code:

 Protected Sub Button10_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button10.Click
        ' create a new XML Document object for each XML file
        If IsPostBack = True Then
            MsgBox("HHHHHH")
            Dim xdDonor As New Xml.XmlDocument
            Dim xdLink As New Xml.XmlDocument
            Dim xdReceiver As New Xml.XmlDocument

            ' load all of the XML documents
            xdDonor.Load(Server.MapPath("~/App_Data/Donor.xml"))
            xdLink.Load(Server.MapPath("~/App_Data/Link.xml"))
            xdReceiver.Load(Server.MapPath("~/App_Data/Receiver.xml"))

            ' I'm faking the text box here...
            Dim TextBoxText As String = "1"

            ' 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='" & TextBoxText & "']")
                ' 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

                'Debug.WriteLine("From Link.xml...")
                'Debug.WriteLine("ReceiverID=" & ReceiverID)
                MsgBox("ReceiverID=" & ReceiverID)
                MsgBox("DonorID=" & DonorID)

                ' 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

                    ' Debug.WriteLine("From Donor.xml...")
                    MsgBox("DonorID=" & DonorID2)
                    MsgBox("Name=" & Name)
                Next

                ' Perform yet another practically identical search on the Receiver XML file
                'For Each xnReceiver As Xml.XmlNode In xdDonor.SelectNodes("/Root/Receiver[ReceiverID='" & ReceiverID & "']")
                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

                    'Debug.WriteLine("From Reciever.xml...")
                    MsgBox("ReceiverID=" & ReceiverID2)
                    MsgBox("Name=" & Name)
                Next
            Next
        End If
    End Sub
SWhouldn't this be:

For Each xdLink As Xml.XmlNode In xdLink.SelectNodes("/Root/Link[ReceiverID='" & TextBoxText & "']")
 instead of:

For Each xnLink As Xml.XmlNode In xdLink.SelectNodes("/Root/Link[ReceiverID='" & TextBoxText & "']")
Well, the code works at my end... (er, well... after I fixed that typo with the "xdReceiver")

I can only assume that the XML files are not in the correct location and are not getting loaded?
The XML files are the ones you posted at the top of this thread!
Hi,

I think it's working, but the comboboxes are still blank, can you please include the code to populate the combo boxes with Receiver and Donor data after I filter the data based on the Textbox value.

Below is the code I initially used to populate the comboboxes when I did not filter the data.

Code:

DonorStream.Load(Server.MapPath("~/App_Data/Donor.xml")) 'My.Resources.Donor)
        RecStream.Load(Server.MapPath("~/App_Data/Receiver.xml")) 'My.Resources.Receiver)
        LinkStream.Load(Server.MapPath("~/App_Data/Link.xml")) 'My.Resources.Link)


        Dim lnk As XmlNodeList = LinkStream.SelectNodes("Root/Link")
        Dim RecName As XmlNodeList = RecStream.SelectNodes("Root/Receiver")
        Dim DonorName As XmlNodeList = DonorStream.SelectNodes("Root/Donor")

        'Create Table
        Dim donorlst As New DataTable()
        donorlst.Columns.Add("ID")
        donorlst.Columns.Add("Name")

        Dim reclst As New DataTable
        reclst.Columns.Add("ID")
        reclst.Columns.Add("Name")

        'Load Link.xml
        Dim MyLink As XDocument = XDocument.Load(Server.MapPath("~/App_Data/Link.xml"))

        'Create varaible CheckForItem to see if I being searched exit in Link.xml
        Dim CheckForItem = (From el In MyLink.Descendants("Link").Elements("ReceiverID") Select el.Value).ToList

        'Loop Through all records in Link.xml and assign first childnode the rID and second childnode to dID
        For Each n As XmlNode In lnk
            If CheckForItem.Contains(Me.TextBox2.Text.ToString) Then
                Dim rID As Integer = Val(n.ChildNodes(0).InnerText)
                Dim dID As Integer = Val(n.ChildNodes(1).InnerText)

                'Loop Through all records in Receiver.xml and if ReceiverID = Textbox2.text and if the firstnode
                For Each node As XmlNode In RecName

                    If node.ChildNodes(0).InnerText = rID.ToString Then
                        reclst.Rows.Add(New Object() {rID, node.ChildNodes(1).InnerText})
                    End If

                Next

            For Each node As XmlNode In DonorName
                If node.ChildNodes(0).InnerText = dID.ToString Then
                    donorlst.Rows.Add(New Object() {node.ChildNodes(0).InnerText, node.ChildNodes(1).InnerText})
                    'donorlst.Rows.Add(New Object() {dID, node.ChildNodes(1).InnerText})
                End If
                Next
            End If
        Next

        CmbDonor.DataSource = donorlst
        CmbDonor.DataTextField = "Name"
        CmbDonor.DataValueField = "ID"
        CmbDonor.DataBind()

        CmbRec.DataSource = reclst
        CmbRec.DataTextField = "Name"
        CmbRec.DataValueField = "ID"
        CmbRec.DataBind()

Thanks

Victor
What?  You're back to your original design... with that LINQ statement that doesn't do what you are expecting it to do?
No, I'm not back to the original design, I just need to fill in the comboboxes after I filter the data, the code you sent me doesn't include the displaying the data in the comboboxes, I'm not sure how to modify my old code to fill in those comboboxes.
    I tried to set the datasources to DonorID2 and ReceiverID2, but it does not work.

        CmbDonor.DataSource = DonorID2
        CmbDonor.DataTextField = "Name"
        CmbDonor.DataValueField = "ID"
        CmbDonor.DataBind()

        CmbRec.DataSource = ReceiverID2
        CmbRec.DataTextField = "Name"
        CmbRec.DataValueField = "ID"
        CmbRec.DataBind()
ASKER CERTIFIED SOLUTION
Avatar of graye
graye
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
It worked Beatifully!!!

I'm trying to move to the next records with the code below for when mutiple matches are found but I'm getting error:

'CmbRec' has a SelectedIndex which is invalid because it does not exist in the list of items.
Parameter name: value

on Line: CmbRec.SelectedIndex = Val(Subnode1.InnerText) - 1

Code:

 Dim NodeCount As Integer = LinkStream.SelectNodes("Root/Link").Count
        If (NodeNumber < NodeCount) Then
            NodeNumber += 1   'Move to some next node
            Dim node As XmlNode = LinkStream.SelectSingleNode("Root/Link[" & NodeNumber & "]")
            Dim Subnode1 As XmlNode = node.ChildNodes(0)
            Dim Subnode2 As XmlNode = node.ChildNodes(1)

            CmbRec.SelectedIndex = Val(Subnode1.InnerText) - 1
            CmbDonor.SelectedIndex = Val(Subnode2.InnerText) - 1
            btnPrev.Enabled = True
            If (NodeNumber = NodeCount) Then
                btnNext.Enabled = False
            End If
        Else
            NodeNumber = 0   ' Reset count so start searching from zero (You can change strategy)
            ' btnNext.Enabled = False
        End If

I will sepend more time to work on MoveNext, MovePrevious, MoveFirst and MoveLast Features, will open a related case if I can't resolve it.

THANK YOU!!!
THANK YOU!!