Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ssis/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在Silverlight中的另一个组合的SelectionChanged事件中获取一个组合中的数据_Silverlight_Silverlight 4.0 - Fatal编程技术网

如何在Silverlight中的另一个组合的SelectionChanged事件中获取一个组合中的数据

如何在Silverlight中的另一个组合的SelectionChanged事件中获取一个组合中的数据,silverlight,silverlight-4.0,Silverlight,Silverlight 4.0,我的应用程序在Silverlightc.Net中 我有一张有三个组合框的表格,国家、州、城市 我的要求是我想在国家/地区组合框的Selectionchanged事件中填充我的州组合框 当用户选择某个国家时,该国家的州应填充在状态组合中 数据库表: 国家/地区表CountryID、CountryName 状态表StateID、StateName、CountryId 城市表CityID、CityName、StateId 从Service.svc.cs文件中的数据库im编码检索值 这是我的密码。此代码

我的应用程序在Silverlightc.Net中

我有一张有三个组合框的表格,国家、州、城市

我的要求是我想在国家/地区组合框的Selectionchanged事件中填充我的州组合框

当用户选择某个国家时,该国家的州应填充在状态组合中

数据库表:

国家/地区表CountryID、CountryName 状态表StateID、StateName、CountryId 城市表CityID、CityName、StateId 从Service.svc.cs文件中的数据库im编码检索值

这是我的密码。此代码将获得国家记录

    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
请建议我更改我的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();
            }

但是这会让我了解政治家中所有的州这也许不能回答你的直接问题,但我相信这是一个更好的解决办法,可以解决你想要实现的目标 让客户端上的国家/地区数据构造具有ObservaleCollection属性,然后使用ElementName绑定将State ComboBox的ItemsSource绑定到SelectedItem。国家/地区ComboBox的状态使用ElementName绑定,那么您就不必担心SelectionChanged事件等。这同样适用于州和城市关系。
作为一个非美国公民,我觉得有义务提醒你,大多数其他国家都没有“国家”:

这可能无法回答你的直接问题,但我相信这是一个更好的解决办法,可以解决你正在努力实现的目标 让客户端上的国家/地区数据构造具有ObservaleCollection属性,然后使用ElementName绑定将State ComboBox的ItemsSource绑定到SelectedItem。国家/地区ComboBox的状态使用ElementName绑定,那么您就不必担心SelectionChanged事件等。这同样适用于州和城市关系。
作为一名非美国公民,我有义务提醒您,大多数其他国家都没有“州”:

供您将来参考,当您在评论中看到可能重复的州时,这将是因为投票结束了该问题。按照提供的链接,将您的答案添加到链接问题中。这将允许关闭愚蠢的副本,在这种情况下,希望在不丢失任何答案的情况下将其删除。谢谢,已重新发布答案如果您的状态表中有CountryID,为什么不将所选国家的CountryID发送到web服务并在服务器上进行筛选?!请不要反复问同一个问题。谢谢
    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();
            }