Populating DropDownList from XML?
-
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
-
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
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... :)
-
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
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 PathanGOD HELP THOSE WHO HELP THEMSELVES