Here is the code for you.
To fill up the database, call the database to populate dropdown.
code behind
protected void Page_Load(object sender, EventArgs e)
{
DropDownList1.Items.Add(new ListItem("Sandip", "1"));
DropDownList1.Items.Add(new ListItem("Jon", "2"));
DropDownList1.Items.Add(new ListItem("Michael", "3"));
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
DropDownList2.Items.Clear();
if (DropDownList1.SelectedIndex == 0)
{
DropDownList2.Items.Add(new ListItem("DOT.NET", "1"));
DropDownList2.Items.Add(new ListItem("C#", "2"));
DropDownList2.Items.Add(new ListItem("ASP.NET", "3"));
DropDownList2.Items.Add(new ListItem("LINQ", "4"));
}
else if (DropDownList1.SelectedIndex == 1)
{
DropDownList2.Items.Add(new ListItem("DOT.NET", "1"));
DropDownList2.Items.Add(new ListItem("VB.NET", "2"));
DropDownList2.Items.Add(new ListItem("ASP.NET", "3"));
}
else if (DropDownList1.SelectedIndex == 2)
{
DropDownList2.Items.Add(new ListItem("PHP", "1"));
DropDownList2.Items.Add(new ListItem("MYSQL", "2"));
}
}
aspx code
<asp:dropdownlist id="DropDownList1" runat="server" autopostback="True" xmlns:asp="#unknown">
onselectedindexchanged="DropDownList1_SelectedIndexChanged">
</asp:dropdownlist>
<br />
<br />
<asp:dropdownlist id="DropDownList2" runat="server" xmlns:asp="#unknown">
</asp:dropdownlist>
cheers