I have the following xml file in key/value pair form:
="1.0"="utf-8"="yes"
<root>
<row>
<var name="CountryId" value="1" />
<var name="Country" value="Afghanistan" />
<var name="FIPS104" value="AF" />
</row>
<row>
<var name="CountryId" value="2" />
<var name="Country" value="Albania" />
<var name="FIPS104" value="AL" />
</row>
<row>
<var name="CountryId" value="3" />
<var name="Country" value="Algeria" />
<var name="FIPS104" value="AG" />
</row>
</root>
I need to load this xml document, process it and populate it in a dropdownlist on a webpage via Microsoft Visual Web Developer 2010.
I was trying to do it via XmlNodeList and looping through each XmlNode, but everything I've tried has given me errors!
This is the code in my .cs file.
protected void SetCountryDropDownList()
{
XmlDocument xmlCountryDocument = new XmlDocument();
xmlCountryDocument.Load(XML_FILE_PATH2);
if (!(xmlCountryDocument == null))
{
XmlNodeList countryList = xmlCountryDocument.SelectNodes("root/row");
foreach (XmlNode countryNode in countryList)
{
if (countryNode.Name == "CountryId")
DropDownListCountry.Items.Add(countryNode.Value.ToString());
}
}
}
This is the code in my .aspx file.
<tr>
<td align="left" class="paddingRight"></td>
<td align="left" class="paddingRight">
<asp:label ID="LabelCountry" class="lbl" text="Country:" runat="server" xmlns:asp="#unknown"></asp:label>
</td>
<td>
<asp:DropDownList ID="DropDownListCountry" class="droplist" xmlns:asp="#unknown" Width="195px"
ToolTip="Select the country where the trailer currently resides" runat="server"
DataTextField="Country" DataValueField="CountryId" AutoPostBack="True"
AppendDataBoundItems="True" onselectedindexchanged="DropDownListCountry_SelectedIndexChanged"></asp:DropDownList>
</td>
<td align="left" class="paddingRight"></td>
</tr>
I know that I'm doing something wrong, but I can't figure it out!
I've tried using IDictionary...i.e.,
IDictionary<string, string> keyValuePairList = new Dictionary<string, string>();
and trying to process it, but I'm coming back with errors.
Any help would be greatly appreciated!!
Thanks!
Cindy