Binding xml to dropdownlist
step1: Open Default.aspx page Drag DropDownList
step2: create Xml file (Register.xml file name)
?xml version=”1.0″ encoding=”utf-8″ ?>
<registration>
<userdata>
<firstname>santhu</firstname>
<mobileno>98480</mobileno>
<country>India</country>
<emailId>santhweb</emailId>
<loginname>santhu</loginname>
<loginPwd>web123</loginPwd>
</userdata>
<userdata>
<firstname>raju</firstname>
<mobileno>98480</mobileno>
<country>India</country>
<emailId>rajuweb</emailId>
<loginname>raju</loginname>
<loginPwd>raju123</loginPwd>
</userdata>
<userdata>
<firstname>kiran</firstname>
<mobileno>99480</mobileno>
<country>India</country>
<emailId>kiranweb</emailId>
<loginname>kiran</loginname>
<loginPwd>kiran222</loginPwd>
</userdata>
</registration>
Step3: Write below code in Page Load
protected void Page_Load(object sender, EventArgs e)
{
DataSet objDs = new DataSet();
//it does not contain any folder
objDs.ReadXml(Server.MapPath(”~/register.xml“));
DropDownList1.DataTextField = “firstname”;
DropDownList1.DataValueField = “mobileno”;
//DropDownList1.DataSource = objDs.Tables[0].DefaultView;
DropDownList1.DataSource = objDs;
DropDownList1.DataBind();
}
Step4: Run your application
Binding Xml Data to checkBoxlist
CheckBoxList1.DataTextField = “firstname”;
CheckBoxList1.DataValueField = “mobileno”;
CheckBoxList1.DataSource = objDs;
CheckBoxList1.DataBind();
