Hi EmadKhan,
Here I have created sample using your xml file to populate WeatherStatus DropDwonList and ProjectClassification DropDwonList.
I hope this will help you out.
HTML
<div>
Weather Status:
<asp:DropDownList ID="ddlWeatherStatus" runat="server">
</asp:DropDownList>
Project Classifications :
<asp:DropDownList ID="ddlProjectClassifications" runat="server">
</asp:DropDownList>
</div>
Code
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
BindFromXml();
}
}
private void BindFromXml()
{
string filePath = Server.MapPath("~/App_Data/SystemConfiguration.xml");
XmlDocument doc = new XmlDocument();
doc.Load(filePath);
int countProjectClassification = doc.GetElementsByTagName("ProjectClassification").Count;
DataTable dtProjectClassification = new DataTable();
dtProjectClassification.Columns.AddRange(new DataColumn[2] { new DataColumn("Id", typeof(int)), new DataColumn("Type", typeof(string)) });
for (int i = 0; i < countProjectClassification; i++)
{
if (doc.GetElementsByTagName("ProjectClassification")[i].HasChildNodes)
{
XmlNodeList node = doc.GetElementsByTagName("ProjectClassification")[i].ChildNodes;
dtProjectClassification.Rows.Add(Convert.ToInt32(node[0].InnerText), node[1].InnerText);
}
}
ddlProjectClassifications.DataSource = dtProjectClassification;
ddlProjectClassifications.DataTextField = "Type";
ddlProjectClassifications.DataValueField = "Id";
ddlProjectClassifications.DataBind();
int countWeatherStatus = doc.GetElementsByTagName("WeatherStatus").Count;
DataTable dtWeatherStatus = new DataTable();
dtWeatherStatus.Columns.AddRange(new DataColumn[2] { new DataColumn("Id", typeof(string)), new DataColumn("Name", typeof(string)) });
for (int j = 0; j < countWeatherStatus; j++)
{
if (doc.GetElementsByTagName("WeatherStatus")[j].HasChildNodes)
{
XmlNodeList node = doc.GetElementsByTagName("WeatherStatus")[j].ChildNodes;
dtWeatherStatus.Rows.Add(node[0].InnerText, node[1].InnerText);
}
}
ddlWeatherStatus.DataSource = dtWeatherStatus;
ddlWeatherStatus.DataTextField = "Name";
ddlWeatherStatus.DataValueField = "Id";
ddlWeatherStatus.DataBind();
}
Screenshot