Populating Dropdownlist Using listbox and listbox using dropdown

Posted by Sandhyab under ASP.NET category on | Points: 40 | Views : 1327
In aspx page take Two dropdowns and one listbox. Here I used xml file to bind the data.
In aspx:
<asp:DropDownList ID="DropDown1" runat="server" AutoPostBack="true" OnSelectedIndexChanged="Displaylistbox" DataTextField="state" DataValueField="state"></asp:DropDownList>
<asp:ListBox ID="listbox1" runat="server" AutoPostBack="true" OnSelectedIndexChanged="DisplaySecondDropDown" DataTextField="city" DataValueField="city"></asp:ListBox>
<asp:DropDownList ID="DropDown2" runat="server" AutoPostBack="true" DataTextField="location" DataValueField="location"></asp:DropDownList>


Code Behind:
protected void PopulateData()
DataTable table = GetData();
DataTable state = table.DefaultView.ToTable(true, "state");
DropDown1.DataSource = state;

private DataTable GetData()
DataSet dset = new DataSet();
DataTable table = dset.Tables[0];
return table;
protected void Displaylistbox(object sender, EventArgs e)
DataTable table = GetData();
string state = DropDown1.SelectedValue;
table.DefaultView.RowFilter = "state='" + state + "'";
listbox1.DataSource = table;

protected void DisplaySecondDropDown(object sender, EventArgs e)
DataTable table = GetData();
string state = listbox1.SelectedValue;
table.DefaultView.RowFilter = "city='" + state + "'";
DropDown2.DataSource = table;

<?xml version="1.0" encoding="utf-8" ?>
<country state="Please Select" city="Please Select" location="Please Select"></country>
<country state="AP" city="HYD" location="PragathiNagar"></country>
<country state="AP" city="KarimNagar" location="Jagityala"></country>
<country state="AP" city="Nizamabad" location="Bodhan"></country>

<country state="WB" city="KOLKATA" location="SALTLAKE"></country>
<country state="WB" city="KARAKPUR" location="IIT"></country>


Thanks & Regards

Comments or Responses

Login to post response