Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Populate ListBox with XML Data?

Populate ListBox with XML Data?

Scheduled Pinned Locked Moved ASP.NET
questionxmlhelptutorial
9 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    chand10
    wrote on last edited by
    #1

    Hi In my application, I have a ListBox which is to be filled with the values in XML file. My application goes like this..... I am getting a State name of USA from the QueryString, with the help of a that QueryString I have to get the Names of Counties of that State, which r in a XML file on to a ListBox. My XML File looks like this AK Alaska Aleutians East AK Alaska Aleutians West ..... ..... AL Alabama Autauga AL Alabama Baldwin ..... ..... GA Georgia Campbell GA Georgia Milton How can I get only County Names of a particular State for this XML file. Suggest me an Example. I have not failed. I've just found 10,000 ways that won't work. -Thomas A. Edison Thank u Chandu

    I P 2 Replies Last reply
    0
    • C chand10

      Hi In my application, I have a ListBox which is to be filled with the values in XML file. My application goes like this..... I am getting a State name of USA from the QueryString, with the help of a that QueryString I have to get the Names of Counties of that State, which r in a XML file on to a ListBox. My XML File looks like this AK Alaska Aleutians East AK Alaska Aleutians West ..... ..... AL Alabama Autauga AL Alabama Baldwin ..... ..... GA Georgia Campbell GA Georgia Milton How can I get only County Names of a particular State for this XML file. Suggest me an Example. I have not failed. I've just found 10,000 ways that won't work. -Thomas A. Edison Thank u Chandu

      I Offline
      I Offline
      Imran Khan Pathan
      wrote on last edited by
      #2

      XmlDataDocument xdoc = new XmlDataDocument(); XmlTextReader Reader = new XmlTextReader(server.MapPath("XML.xml")); xdoc.DataSet.ReadXml(Reader, XmlReadMode.InferSchema); ddl.datasource=xdoc.dataset; ddl.DataTextField="CountryName"; ddl.databind(); Best Regard Pathan

      ---------------------------------------------------

      C 1 Reply Last reply
      0
      • I Imran Khan Pathan

        XmlDataDocument xdoc = new XmlDataDocument(); XmlTextReader Reader = new XmlTextReader(server.MapPath("XML.xml")); xdoc.DataSet.ReadXml(Reader, XmlReadMode.InferSchema); ddl.datasource=xdoc.dataset; ddl.DataTextField="CountryName"; ddl.databind(); Best Regard Pathan

        ---------------------------------------------------

        C Offline
        C Offline
        chand10
        wrote on last edited by
        #3

        Thank u Imran Khan Pathan for u reply. It is giving only the Counties of only one State i.e first in the list. I want to get Counties of different States with the help of a QueryString. Where I have to give this QueryString to get the Data for Different State's Counties

        I have not failed. I've just found 10,000 ways that won't work. -Thomas A. Edison Thank u Chandu

        I 1 Reply Last reply
        0
        • C chand10

          Hi In my application, I have a ListBox which is to be filled with the values in XML file. My application goes like this..... I am getting a State name of USA from the QueryString, with the help of a that QueryString I have to get the Names of Counties of that State, which r in a XML file on to a ListBox. My XML File looks like this AK Alaska Aleutians East AK Alaska Aleutians West ..... ..... AL Alabama Autauga AL Alabama Baldwin ..... ..... GA Georgia Campbell GA Georgia Milton How can I get only County Names of a particular State for this XML file. Suggest me an Example. I have not failed. I've just found 10,000 ways that won't work. -Thomas A. Edison Thank u Chandu

          P Offline
          P Offline
          Piyush Vardhan Singh
          wrote on last edited by
          #4

          use this code to bound ur dropdownlist anjoy the coding Dim _Doc As New System.Xml.XmlDocument _Doc.Load("file:///C:/testxml.xml") Dim NodeList As System.Xml.XmlNodeList = _Doc.SelectNodes("/USA/CountyUSA/CountyName") For Each node As System.Xml.XmlNode In NodeList Dim ss As String = node.InnerText DropDownList1.DataSource = ss DropDownList1.DataBind() Next

          Piyush Vardhan Singh Programmer TAS NewDelhi India

          P 1 Reply Last reply
          0
          • P Piyush Vardhan Singh

            use this code to bound ur dropdownlist anjoy the coding Dim _Doc As New System.Xml.XmlDocument _Doc.Load("file:///C:/testxml.xml") Dim NodeList As System.Xml.XmlNodeList = _Doc.SelectNodes("/USA/CountyUSA/CountyName") For Each node As System.Xml.XmlNode In NodeList Dim ss As String = node.InnerText DropDownList1.DataSource = ss DropDownList1.DataBind() Next

            Piyush Vardhan Singh Programmer TAS NewDelhi India

            P Offline
            P Offline
            Piyush Vardhan Singh
            wrote on last edited by
            #5

            where i stored CountyName in ss string. u store all CountyName in hash table or collection then bind drop down list(out side the for each)

            Piyush Vardhan Singh Programmer TAS NewDelhi India

            C 1 Reply Last reply
            0
            • C chand10

              Thank u Imran Khan Pathan for u reply. It is giving only the Counties of only one State i.e first in the list. I want to get Counties of different States with the help of a QueryString. Where I have to give this QueryString to get the Data for Different State's Counties

              I have not failed. I've just found 10,000 ways that won't work. -Thomas A. Edison Thank u Chandu

              I Offline
              I Offline
              Imran Khan Pathan
              wrote on last edited by
              #6

              U can select using DataTabale.Select Method DataTable dt=ds.table[0]; datarow[] dr=dt.select("State='"+var+"'"); Best Regard Pathan

              ---------------------------------------------------

              C 1 Reply Last reply
              0
              • P Piyush Vardhan Singh

                where i stored CountyName in ss string. u store all CountyName in hash table or collection then bind drop down list(out side the for each)

                Piyush Vardhan Singh Programmer TAS NewDelhi India

                C Offline
                C Offline
                chand10
                wrote on last edited by
                #7

                Thank u for u r reply Piyush Vardhan Singh But I am having all the County Names of different States in a single XML file. How can I get County Names of each State in order to bind that Data to ListBox. As I said earlier I getting that State Name in a QueryString, with that Name in the QueryString I have to get the Couty Names of that State. How can I make this kind of selection.

                I have not failed. I've just found 10,000 ways that won't work. -Thomas A. Edison Thank u Chandu

                1 Reply Last reply
                0
                • I Imran Khan Pathan

                  U can select using DataTabale.Select Method DataTable dt=ds.table[0]; datarow[] dr=dt.select("State='"+var+"'"); Best Regard Pathan

                  ---------------------------------------------------

                  C Offline
                  C Offline
                  chand10
                  wrote on last edited by
                  #8

                  Ok How can I use this in your given code.

                  I have not failed. I've just found 10,000 ways that won't work. -Thomas A. Edison Thank u Chandu

                  I 1 Reply Last reply
                  0
                  • C chand10

                    Ok How can I use this in your given code.

                    I have not failed. I've just found 10,000 ways that won't work. -Thomas A. Edison Thank u Chandu

                    I Offline
                    I Offline
                    Imran Khan Pathan
                    wrote on last edited by
                    #9

                    DataSet ds=xdoc.dataset; DataTable dt=ds.table[0]; DataRow[] dr=dt.select("State='"+statename+"'"); DataTable dt1=new DataTable(); foreach(DataRow dr1 in dr) { dt1.Rows.Add(dr1) } ddl.DataSource=dt1; ddl.DataTextField="CountryName"; ddl.databind(); Best Regard Pathan

                    ---------------------------------------------------

                    1 Reply Last reply
                    0
                    Reply
                    • Reply as topic
                    Log in to reply
                    • Oldest to Newest
                    • Newest to Oldest
                    • Most Votes


                    • Login

                    • Don't have an account? Register

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • World
                    • Users
                    • Groups