protected void gvTeacherGroup_RowUpdating(object sender, GridViewUpdateEventArgs e) { String id = gvTeacherGroup.DataKeys[e.RowIndex].Value.ToString(); String strName = ((TextBox)gvTeacherGroup.Rows[e.RowIndex].Cells[2].FindControl("tbTeacherGroupName")).Text.ToString().Trim(); String managerName = ((TextBox)gvTeacherGroup.Rows[e.RowIndex].Cells[3].FindControl("tbLeaderName")).Text.ToString().Trim(); int managerId = -1; try { Users user = BLL.admin.user.UserManagement.getUserByName(managerName); if (user != null) managerId = user.Key; } catch (Exception ex) { }; t_Teacher_Group tg = new t_Teacher_Group(); tg.Id = Convert.ToInt32(id); tg.Name = strName; tg.LeaderId = managerId; BLL.admin.TeacherGroup.TeacherGroupManagement.updateTeacherGroup(tg); gvTeacherGroup.EditIndex = -1; //将GridView控件恢复为编辑前的状态。即更新完了就得回到非编辑状态 databind(); //更新完了之后,就得重新绑定,即重新从数据库中读取刚才更新的数据。 }
protected void btAdd_Click(object sender, EventArgs e) { t_Teacher_Group tGroup = new t_Teacher_Group(); tGroup.Name = tbGroupName.Text; BLL.admin.TeacherGroup.TeacherGroupManagement.createTeacherGroup(tGroup); lbMessage.Text = "添加成功!"; databind(); }
public static bool createTeacherGroup(t_Teacher_Group group) { using (DataClassesEduDataContext dc = new DataClassesEduDataContext()) { dc.t_Teacher_Group.InsertOnSubmit(group); dc.SubmitChanges(); return true; } }
public static bool updateTeacherGroup(t_Teacher_Group group) { using (DataClassesEduDataContext dc = new DataClassesEduDataContext()) { t_Teacher_Group tGroup = dc.t_Teacher_Group.Where(u => u.Id == group.Id).Single(); tGroup.Name = group.Name; tGroup.LeaderId = group.LeaderId; dc.SubmitChanges(); return true; } }