Hi,
Try this code. It will work.
XML File:
<?xml version="1.0" encoding="utf-8" ?>
<root>
<country id="india">
<state>Andhra</state>
<state>Tamilnadu</state>
</country>
<country id="America">
<state>Washingtone</state>
<state>Test</state>
</country>
</root>
Code:
protected void Page_Load(object sender, EventArgs e)
{
if(!IsPostBack)
{
DataSet ds = new DataSet();
ds.ReadXml(Server.MapPath("XMLFile.xml"));
DropDownList1.DataTextField = "id";
DropDownList1.DataValueField = "country_Id";
DropDownList1.DataSource = ds;
DropDownList1.DataBind();
DropDownList1.SelectedIndex = 0;
Bind();
}
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
Bind();
}
private void Bind()
{
DataSet ds = new DataSet();
ds.ReadXml(Server.MapPath("XMLFile.xml"));
DropDownList2.DataTextField = "state_Text";
DropDownList2.DataValueField = "state_Text";
DataView view = new DataView(ds.Tables["state"]);
view.RowFilter = "country_Id='" + DropDownList1.SelectedValue + "'";
DropDownList2.DataSource = view;
DropDownList2.DataBind();
}
If it is useful don't forget to mark as answer.
Thanks & Regards,
Software Engineer,
Pradeep Kumar
reddysankark-13471, if this helps please login to Mark As Answer. | Alert Moderator