How to sort Name by asc from XML file and populate the dropdown?

This is the frequently asked question in interview. “Write a program to sort the Empname by asc from Xml file and populate the dropdown”.

We can do using 2 approach
1. using dataset and dataview concept
2. using Linq to Xml concept

Here i m writting code using dataset and dataview concept
Step1: Create some Xml file like this

<?xml version="1.0" encoding="utf-8" ?>

Step 2: Write the C# code in codebehind file like this

protected void Page_Load(object sender, EventArgs e)

string filepath = Server.MapPath("../Emp.xml");
using (DataSet ds = new DataSet())
DataView dv = new DataView();
dv =ds.Tables["Emp"].DefaultView;
dv.RowFilter = "Name='Ram'";
dv.Sort = "Address Asc";
DropDownList1.DataSource = dv;
DropDownList1.DataTextField = "Address";
DropDownList1.DataValueField = "Id";



I hope it will help to someone.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.