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. Populating DropDownList from XML?

Populating DropDownList from XML?

Scheduled Pinned Locked Moved ASP.NET
xmlhelptutorialquestion
3 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 I am trying an application, in that their are two DropDownList controls.Both are to be filled with the XML node items.With the selection change in the first DropDownList, second one should be populate with the corresponing result of the selection one. I am able to populate two DropDownLists with all the nodes in the XML file but I am not getting the particular selection of First DropDownList. My XML File is something like this..... AKAleutians East

    AKAleutians West

    AKAnchorage

    ALJackson

    ALJefferson

    ALLamar

    ALLauderdale

    All StateCode will be displayed on DropDownList1 and for the corresponding StateCode selection all the CountyNames in that StateCode Should be displayed on DropDownList2,this I am not getting. Help me out suggest me an example if possible. I have not failed. I've just found 10,000 ways that won't work. -Thomas A. Edison Thank u Chandu

    V I 2 Replies Last reply
    0
    • C chand10

      Hi I am trying an application, in that their are two DropDownList controls.Both are to be filled with the XML node items.With the selection change in the first DropDownList, second one should be populate with the corresponing result of the selection one. I am able to populate two DropDownLists with all the nodes in the XML file but I am not getting the particular selection of First DropDownList. My XML File is something like this..... AKAleutians East

      AKAleutians West

      AKAnchorage

      ALJackson

      ALJefferson

      ALLamar

      ALLauderdale

      All StateCode will be displayed on DropDownList1 and for the corresponding StateCode selection all the CountyNames in that StateCode Should be displayed on DropDownList2,this I am not getting. Help me out suggest me an example if possible. I have not failed. I've just found 10,000 ways that won't work. -Thomas A. Edison Thank u Chandu

      V Offline
      V Offline
      valerian precop
      wrote on last edited by
      #2

      Here is one method you could use: 1. create a "ListItemCollection" (eg. lstAllNodes) object and populate it with all the pair values (StateCode,CountyName) from your XML (the text should be StateCode and the value should be CountyName). 2. After that you should do something like this protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e) { string sText = DropDownList1.SelectedItem.Text; ListItemCollection lstCountyName = new ListItemCollection(); foreach (ListItem lstTempItem in lstAllNodes) { if (lstTempItem.Text == sText) { lstCountyName.Add(lstTempItem); } } DropDownList2.DataSource = lstCountyName; DropDownList2.DataBind(); } Where: -lstAllNodes is the ListItemCollection object populated with all the nodes like I said at 1. -DropDownList1 is your first drop down list with StateCodes (be carefull to have it runat server and set AutoPostBack="true" so that the SelectedIndexChanged event may trigger) -lstCountyName is a second ListItemCollection (it is a temporary object and it's empty at first) it's used to bind the second drop down list with the required values -DropDownList2 your second drop down list with CountyNames

      Just call me Valy... :)

      1 Reply Last reply
      0
      • C chand10

        Hi I am trying an application, in that their are two DropDownList controls.Both are to be filled with the XML node items.With the selection change in the first DropDownList, second one should be populate with the corresponing result of the selection one. I am able to populate two DropDownLists with all the nodes in the XML file but I am not getting the particular selection of First DropDownList. My XML File is something like this..... AKAleutians East

        AKAleutians West

        AKAnchorage

        ALJackson

        ALJefferson

        ALLamar

        ALLauderdale

        All StateCode will be displayed on DropDownList1 and for the corresponding StateCode selection all the CountyNames in that StateCode Should be displayed on DropDownList2,this I am not getting. Help me out suggest me an example if possible. 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
        #3

        Try this function Dataset XMLfile() { XmlDataDocument xdoc = new XmlDataDocument(); return xdoc.DataSet.ReadXml(Server.MapPath("XMl.xml")); } protected void Page_Load(object sender, EventArgs e) { dataset ds=XMLfile(); dd1.datasource=ds; dd1.datatextField="StateCode"; dd1.databind(); } protected void dd2_SelectedIndexChanged(object sender, EventArgs e) { dataset ds=XMLfile(); datarow[] dr=ds.table.select("StateCode='"+dd1.selectedItem.Text+"'"); datatable tb1; foreach(datarow dr1 in dr) tb1.ImportRow(dr1); dd2.datasource=tb1; dd2.datatextfield="CountyName" dd2.databind(); } Best Regard Pathan

        GOD HELP THOSE WHO HELP THEMSELVES

        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