silverght 中 修改DataGrid 中数据, DataGrid 中数据,及时刷新问题
public class Student { private int id; public int Id { get { return id; } set { id = value; } } private string className; public string ClassName { get { return className; } set { className = value; } } public Student() { } }
public ObservableCollection<SUser> GetAllUser() { ObservableCollection<SUser> Lsu = new ObservableCollection<SUser>(); string sql = "select * from SUser"; using(SqlDataReader sdr=DBHelper.ExecuteReader(DBHelper.ConnectionStringLocalTransaction,CommandType.Text,sql,null)) { while(sdr.Read()) { SUser su = new SUser(); su.Id = Convert.ToInt32(sdr["Id"]); su.Name = Convert.ToString(sdr["Name"]); su.Phone = Convert.ToString(sdr["Phone"]); su.Sex = Convert.ToString(sdr["Sex"]); su.StudentID = Convert.ToInt32(sdr["StudentID"]); su.Adress = Convert.ToString(sdr["Adress"]); su.Age = Convert.ToString(sdr["Age"]); Lsu.Add(su); } } return Lsu; }
public class SUserManager { SUserService ssu = new SUserService(); public ObservableCollection<SUser> GetAllUser() { return ssu.GetAllUser(); } /// <summary> /// 获取所有用户信息 /// </summary> /// <returns></returns> public List<SUser> GetAllUserByClassID(int stuID) { return ssu.GetAllUserByClassID(stuID); } /// <summary> /// 获取所有用户信息,参数为用户对象 /// </summary> /// <returns></returns> public List<SUser> GetAllUserByClassSex(SUser sue) { return ssu.GetAllUserByClassSex(sue); } /// <summary> /// 修改用户的信息 /// </summary> /// <param name="user"></param> /// <returns></returns> public int UpdataUser(SUser user) { return ssu.UpdataUser(user); } }
private void btnUpdate_Click(object sender, RoutedEventArgs e) { SUser u = new SUser(); u.Name = this.txtSN.Text.ToString(); u.Sex = this.txtSx.Text.ToString(); u.Adress = this.txtAd.Text.ToString(); u.Age = this.txtAg.Text.ToString(); u.Phone = this.txtPh.Text.ToString(); u.StudentID = Convert.ToInt32(this.txtCl.Text.ToString()); u.Id = ((SUser)(this.dgvShow.SelectedItem)).Id; DBServiceClient proxyUpdateUser = new DBServiceClient("BasicHttpBinding_IProductService"); //用一个方法 new 一次 proxyUpdateUser.UpdataUserAsync(u); proxyUpdateUser.UpdataUserCompleted += new EventHandler<UpdataUserCompletedEventArgs>(proxyUpdateUser_UpdataUserCompleted); } void proxyUpdateUser_UpdataUserCompleted(object sender, UpdataUserCompletedEventArgs e) { this.dgvShow.SelectedItem = e.Result; this.UpdateLayout(); }
dgvShow.ItemsSource = null;dgvShow.ItemsSource = e.result;