ComboBox Issues are back.
My application is in Silverlight with C#.Net code(VS2010). I have three ComboBoxes.
- Country
- State
- City.
Now my requirement is when I select Country from my ComboBox(Ex:India) then all the states in India should be populated in State ComboBox and when I select some other country that countries states should be populated.For this I have created my Database in this manner only with giving UniqueID to each country.
My Database tables are designed this way
- CountryTable(Coun开发者_开发技巧tryId,CountryName)
- StateTable(StateId,StateName,CountryId)
- CityTable(CityId,CityName,StateName)
This way I have designed my DB.
I have coded in Service.svc.cs file to populate my Comboboxes.
Code in Service.svc.cs
[OperationContract]
public List<GetCountry> GetCountryRecord()
{
using (Entities context = new Entities())
{
return (from c in context.CountryMaster
select new GetCountry
{
Country = c.CountryName,
}).ToList<GetCountry>();
}
}
public class GetCountry
{
public string Country { get; set; }
}
End of Service.svc.cs Code.
Code in the Form.Xaml.cs
var client = new ServiceReference1.AlumniServiceClient();
client.GetCountryRecordCompleted += (s, ea) =>
{
cboCountry.ItemsSource = ea.Result.Select(b => b.Country).ToList();;
};
client.GetCountryRecordAsync();
This is how im populating my combo boxes. Now i want that the State values should change depending on the country selected and similarly the city combobox values should change depending on the state selected.
How can i achieve this by using this code and not recoding too many things.
Please guide wit code...
Either on the SelectionChanged
event of the first ComboBox
or when the bound setter gets called make the database call to populate the next ComboxBox
in the sequence.
So initially you populate the country combo. Then when the user selects the country this sends the database request to populate the state combo. As this all happens asynchronously you're not tying up the UI while it happens.
精彩评论