내 응용 프로그램은 내가 세 가지 콤보 상자, 국가, 주, 도시와 형태가 실버 라이트 (C#을 닷넷)는 실버
입니다.
필자의 요구 사항은 국가의 선택 변경 이벤트 콤보 상자에서 내 상태 콤보 상자를 채우고 싶습니다.
사용자가 해당 국가의 주를 합산하여 채워야하는 국가를 선택한 경우.
데이터베이스 테이블 :
- 나라 테이블 - (CountryID, COUNTRYNAME)
- 주 테이블 - (StateID, StateName, CountryId)
- 시 테이블 - (CityID, CityName이, StateId)
Service.svc.cs 파일에서 코딩 한 데이터베이스에서 값을 검색하려면
이것은 내 코드입니다. 이 코드는 국가 기록을 얻을 것입니다.
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. 그것은 국가 콤보 상자에서 국가를
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**
이 국가 콤보
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();
}
의에서 selectionChanged 이벤트에서 Form.xaml.cs 내 코드는하지만이 StatesMaster
국가 테이블에 국가 ID가 있습니다. 선택한 국가의 국가 ID를 보내지 않는 이유는 무엇입니까? 웹 서비스 및 서버의 필터?! – AbdouMoumen
같은 질문을 계속 반복해서하지 마십시오. 감사합니다 – Kev