Populate more than one datas in second ddllist by selcting single data in first ddlist frm datatable

Posted by Shailesh21235 under ASP.NET on 6/4/2012 | Points: 10 | Views : 832 | Status : [Member] | Replies : 3
CountryTable
DataRow drCountryRow1 = dtCountryTable.NewRow();
drCountryRow1["CountryId"] = "1";
drCountryRow1["CountryName"] = "India";
dtCountryTable.Rows.Add(drCountryRow1);

DataRow drCountryRow2 = dtCountryTable.NewRow();
drCountryRow2["CountryId"] = "2";
drCountryRow2["CountryName"] = "Usa";
dtCountryTable.Rows.Add(drCountryRow2);

CityTAble
DataRow drCityRow1 = dtCityTable.NewRow();
drCityRow1["CityId"] = "1";
drCityRow1["CityName"] = "Delhi";
dtCityTable.Rows.Add(drCityRow1);

DataRow drCityRow2 = dtCityTable.NewRow();
drCityRow2["CityId"] = "2";
drCityRow2["CityName"] = "Mumbai";
dtCityTable.Rows.Add(drCityRow2);

DataRow drCityRow3 = dtCityTable.NewRow();
drCityRow3["CityId"] = "3";
drCityRow3["CityName"] = "Goa";
dtCityTable.Rows.Add(drCityRow3);

DataRow drCityRow4 = dtCityTable.NewRow();
drCityRow4["CityId"] = "4";
drCityRow4["CityName"] = "NewYork";
dtCityTable.Rows.Add(drCityRow4);

DataRow drCityRow5 = dtCityTable.NewRow();
drCityRow5["CityId"] = "5";
drCityRow5["CityName"] = "Texas";
dtCityTable.Rows.Add(drCityRow5);

DataRow drCityRow6 = dtCityTable.NewRow();
drCityRow6["CityId"] = "5";
drCityRow6["CityName"] = "LasVegas";
dtCityTable.Rows.Add(drCityRow6);

I have added these datas from datatable and they are displayed in dropdownlists....
ddlCountry.DataSource = CreateCountryTable();
ddlCountry.DataTextField = "CountryName";
ddlCountry.DataValueField = "CountryId";
ddlCountry.DataBind();
but when i select one country then their cities should be displayed in second dropdownlist..How to display multiple datas in 2nd ddllist????




Responses

Posted by: Ashoknalam on: 6/4/2012 [Member] Starter | Points: 25

Up
0
Down
First of all you should have CoutnryID reference in citytable so that
from the first dropdown if you select countryid based on selection id fill the city dropdown.






Ashok Nalam

Shailesh21235, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Shailesh21235 on: 6/4/2012 [Member] Starter | Points: 25

Up
0
Down
how to add refernece in city datatable???
could you provide me with a sample code???

Shailesh21235, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Ajay.Kalol on: 6/4/2012 [Member] Starter | Points: 25

Up
0
Down


DataRow drCityRow1 = dtCityTable.NewRow();

drCityRow1["CityId"] = "1";
drCityRow1["CityName"] = "Delhi"
drCityRow1["CountryID"] = "2"; // Add CountryID Column in City table for Relation Between City And Country
dtCountryTable.Rows.Add(drCountryRow2);


When You want City By Country then
Use this :
Dim Drow() As DataRow

Drow = dtCityTable.Select("CountryID = "+ DDLCountry.selectedValue.tostring());


Ajay
ajaypatelfromsanthal.blogspot.in

Shailesh21235, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response