2
Answers

How I get data alphabatically from xml file in Listbox

Tanmay Sarkar

Tanmay Sarkar

13y
3.7k
1
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)