• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 311
  • Last Modified:

Help with loopingf through GridView and retreiving IDs from xml file or creating new IDs if data does not exist


I am using the code below to loop through a listbox to  retreive existing ID(Part A) or create new IDs (Part B).

How do I modify it for a GridView (Windows App, VS 2010)

For x As Integer = 0 To C1NSN.Items.Count - 1

                If CheckForNSNFix.Contains(C1NSN.Items(x).ToString) Then
                    For Each xnLink As Xml.XmlNode In xdNSN.SelectNodes("/Root/NSNTable[NSN='" & C1NSN.Items(x).ToString & "']")
                        NSN_ID = xnLink.SelectSingleNode("NSN_ID").InnerText
                        If NSN_ID <> "" Then
                            CD = NSN_ID
                            If u > 0 Then
                                num1 = num1 & "" & CD & ","
                                num1 = CD & ","
                            End If
                            u = u + 1
                        End If
                End If

'Part B:
            'Assign ID to data not already in XML file
            For x As Integer = 0 To C1NSN.Items.Count - 1
                If Not CheckForNSNFix.Contains(C1NSN.Items(x).ToString) Then
                    Dim xNew As XElement = New XElement(xtable)
                    xNew.Add(New XElement(xid, num))
                    xNew.Add(New XElement(curXYZ, C1NSN.Items(x)))
                    MyFix.Save((Application.StartupPath + "\App_Data\" & curXYZ & ".xml"))
                    If uu > 0 Then
                        num2 += num & ","
                        num2 = num & ","
                    End If
                    uu = uu + 1
                    num = num + 1
                End If

            searchIdNSN = num1 & num2
  • 2
1 Solution
Meir RivkinFull stack Software EngineerCommented:
Assuming C1NSN is your gridview, simply replace C1NSN.Items with C1NSN.Rows
Meir RivkinFull stack Software EngineerCommented:
Btw, i assumed that your id is in 1st column, otherwise u need to specify the column as well:
So instead of C1NSN.Items(x).ToString)
Use this:

Or by column name:
vcharlesAuthor Commented:
Thank You!
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Train for your Pen Testing Engineer Certification

Enroll today in this bundle of courses to gain experience in the logistics of pen testing, Linux fundamentals, vulnerability assessments, detecting live systems, and more! This series, valued at $3,000, is free for Premium members, Team Accounts, and Qualified Experts.

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