我在Xamarin android應用程序中使用了一個簡單的wcf web服務。我有GetAllUser函數來從數據庫中檢索所有用戶。用wcf web服務檢索數據綁定微調框
我可以使用我的Xamarin android應用程序插入用戶。 但我對如何綁定從Web服務檢索到的數據與Xamarin android中的微調控件無能爲力。 我在互聯網上搜索了很多地方,但我仍然沒有辦法綁定我的微調與網絡服務。
namespace WcfServiceSunday
{
public class ServiceSunday : IServiceSunday
{
public List<Employee> GetAllEmployee()
{
List<Employee> employee = new List<Employee>();
string constring = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
SqlConnection con = new SqlConnection(constring);
con.Open();
string qry = "select * from EmpDetail";
SqlCommand cmd = new SqlCommand(qry, con);
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
Employee emp = new Employee();
emp.EmpNo = dr.GetInt32(0);
emp.Name = dr.GetString(1);
emp.Empcode = dr.GetString(2);
emp.keywords = dr.GetString(3);
emp.mobile = dr.GetString(4);
employee.Add(emp);
}
con.Close();
return employee;
}
以上是我的Web服務,用於從數據庫中選擇所有用戶。 我想綁定微調器並在我的微調控件中顯示用戶名。
以下是我的按鈕單擊事件來填充微調框。
btn.Click += (sender, e) => {
Employee emp = new Employee();
GridView grdvw = FindViewById<GridView>(Resource.Id.grd);
IList<Employee> employ = new List<Employee>();
employ = sc.GetAllEmployee("");
Spinner sp = FindViewById<Spinner>(Resource.Id.spinner);
sp.Adapter = new ArrayAdapter(this,Android.Resource.Layout.SimpleSpinnerItem ,employ.ToList());
};
我能夠填充Web服務的微調,但在spineer 顯示的數據是這樣的:
"WcfServiceSunday.Employee"
我在MTHE微調降得到這上面值下降,而不是名稱我的數據庫中有用戶 。
如何用用戶名填充微調框?
我編輯了我的代碼並再次發佈。我想用我的數據庫中的用戶名填充我的微調器,但我將微調項目看作「WcfServiceSunday.Employee」。 –
這可能是由於您將整個'Employee'對象而不是其'Name'屬性分配給'TextView'。查看我編輯的答案,或提供更多信息,說明您如何解決我在'GetDropDownView'中的'Text'屬性分配中引入的小型複製/粘貼錯誤。 – Cheesebaron
我還沒有試過你的代碼。我一定會嘗試一下。我想知道如何使用我的代碼從「WcfServiceSunday.Employee」中選擇每個名稱。因爲我使用了相同的代碼來綁定網頁中的下拉列表。 Dropdownlist有「datavaluefield」和「datatextfield」分配給他們從他們工作的數據庫中獲取什麼值。這怎麼能在微調中完成呢? –