我目前有一个按钮的以下代码。消息框显示SilverlightApplication2.ServiceReference2.Employee
而不是用户选择的文本字符串。WCF 服务正在填充组合框项。结果,我无法将其传递给 Async 调用。如何获取用户选择的字符串?
private void btnAdd_Click(object sender, RoutedEventArgs e)
{
object selectedItem = comobo1.SelectedItem.ToString();
MessageBox.Show(selectedItem.ToString());
var proxy = new Service1Client();
proxy.GetAllEmployeesCompleted += proxy_GetAllEmployeesCompleted;
proxy.GetAllEmployeesAsync(selectedItem.ToString());
}
我的服务参考看起来像
公共类下拉{
[OperationContract]
public ObservableCollection<Employee> GetAllBrands()
{
var empstwo = new ObservableCollection<Employee>();
string connect = ConfigurationManager.ConnectionStrings["yoyo"].ToString();
using (var con = new OdbcConnection(connect))
{
//now you can try
//wait. To accept a param from main page, u need to create a method to accept that param first.
//I think you should put this in service1.svc.cs
string query = "Select distinct(brand) FROM pivottable";
var cmd = new OdbcCommand(query, con);
con.Open();
using (var dr = cmd.ExecuteReader())
{
while (dr.Read())
{
var emp = new Employee();
emp.ComboData = dr.GetStringOrNull(0);
empstwo.Add(emp);
}
}
}
return empstwo;
}
}
这是员工类。在此字符串中,ComboData 包含填充我的下拉列表的品牌列表
public class Employee
{
public int EmployeeID { get; set; }
public string FirstName { get; set; }
public Uri ImageURI { get; set; }
public string ComboData { get; set; }
}