私のアプリケーションは、私は3つのコンボボックス、国、州、市とフォームを持っているのSilverlight(C#の純)は、Silverlightの
です。
私の必要条件は、国の選択変更イベントコンボボックスに私の状態コンボボックスを設定したいです。
ユーザーが国を選択したときに、その国の州を州のコンボに移入する必要があります。
データベーステーブル:
- 国卓上(CountryID、COUNTRYNAME)
- 州卓上(STATEID、ステート名、CountryId)
- 市卓上(CityID、CityName、STATEID)
Service.svc.csファイルのDatabase im codingで値を取得するには
これは私のコードです。このコードはカントリーレコードを取得します。
public class GetCountry
{
public string CountryName { get; set; }
}
[OperationContract]
public List<GetCountry> GetCountryRecord()
{
using (Entities context = new Entities())
{
return (from c in context.CountryMasters
select new GetCountry
{
CountryName = c.CountryName,
}).ToList<GetCountry>();
}
}
//Code to Get State from State_Master table
public class GetState
{
public string StateName { get; set; }
}
[OperationContract]
public List<GetState> GetStateRecord(int countryId)
{
using (Entities context = new Entities())
{
return (from c in context.StateMasters
select new GetState
{
StateName = c.StateName,
}).ToList<GetState>();
}
}
//End of State Code
これはForm.xaml.cs.xのコードです。これは、国のコンボボックス
client = new ServiceReference1.AlumniServiceClient();
client.GetCountryRecordCompleted += (s, ea) =>
{
cboCountry.ItemsSource = ea.Result.Select(b => b.CountryName).ToList();
};
client.GetCountryRecordAsync();
の国々に移入されます、私は私の必要な結果や、それを得るために他の方法を得るために、私Service.svc.csファイルにクエリの変更提案してください。
return (**from c in context.StateMasters
select new GetState**
これは、国コンボボックスのselectionChangedイベントでForm.xaml.csで私のコード
private void cboCountry_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
var client = new ServiceReference1.AlumniServiceClient();
client.GetStateRecordCompleted += (s, ea) =>
{
cboState.ItemsSource = ea.Result.Select(b => b.StateName).ToList(); };
client.GetStateRecordAsync();
}
である。しかし、これは私にStatesMaster
StateテーブルにCountryIDがあります。 Webサービスとサーバー上のフィルタ? – AbdouMoumen
同じ質問を何度も何度も繰り返してはいけません。ありがとう – Kev