
Hi Amar,
Hi
First Create a Table with a Name States .It contains two columns as stateid and statename
stateid statename
----------------------
1 Andhra Pradesh
2 Karnataka
3 Maharastra
Next Create Another table with a name citys .It contains stateid and cityname columns.
stateid cityname
-------------------------
1 Hyderabad
2 Banglore
3 Mumbai
Drag and Drop Two Dropdownlist.
In first DropdownList retrive the data from a table states as follows
write in PageLoed Event:
SqlCommand cmd=new SqlCommand("select * from states",conn);
SqlDataReader reader=cmd.ExecuteReader();
DropDownList1.Items.Cleer();
while(reader.Read())
{
ListItem li=new ListItem();
li.Value=reader["stateid"];
li.Text=reader["statename"];
DropDownList1.Items.Add(li);
}
When you select a State the following Capital citys have to display in second dropdownlist2
so Doubleclik on DropdownList1 and write the below code:
SqlCommand conn=new SqlCommand("your connection");
conn2.Open();
SqlCommand cmd2=new SqlCommand("select * from citys where stateid="+ DropdownList1.SelectedValue+",conn2);
SqlDataReader reader2=cmd2.ExecuteReader();
DropDownList2.Items.Clear();
while(reader2.Read())
{
ListItem li2=new ListItem();
li2.Value=reader2["stateid"];
li2.Text=reader2["cityname"];
DropDownList2.Items.Add(li2);
} Syed Shakeer Hussain
Amar888, if this helps please login to Mark As Answer. | Alert Moderator