Tanmay Sarkar

Tanmay Sarkar

  • NA
  • 1.5k
  • 1m

How I get data alphabatically from xml file in Listbox

Aug 7 2010 12:53 AM
I want to set asending/desending order (name) in my listbox contains all name 

Here is my xml file
 <?xml version="1.0"?>
<phonebooklist>
<pbdata>
<name>Tanmay</name>
<contact>1324569780</contact>
</pbdata>
<pbdata>
<name>Ranjan</name>
<contact>8956231447</contact>
</pbdata>
<pbdata>
<name>Tamojit</name>
<contact>342352</contact>
</pbdata>
<pbdata>
<name>deba</name>
<contact>666666</contact>
</pbdata>
</phonebooklist>

I can get name by:

 XmlReader xr = XmlReader.Create("test.xml");
while (xr.Read())
{
if (xr.NodeType == XmlNodeType.Element && xr.Name == "name")
listBox1.Items.Add(xr.ReadElementString());
else
xr.Read();
}

but how i set it alphabetically?

Thank you in advance! :)

Answers (2)