protected void btnEidt_Click(object sender, EventArgs e) { int id = int.Parse(Request["id"].ToString()); UsersDataContext lq = new UsersDataContext(); var users = from gt in lq.Users where gt.uID == id select gt; foreach (Users user in users) { user.uName = txtuName.Text; user.uPwd = txtuPwd.Text; user.uRealName = txtuRealName.Text; user.uSex = rbluSex.SelectedValue; user.uAge = Convert.ToInt16(txtuAge.Text); for (int i = 0; i < cbluHobby.Items.Count; i++) { if (cbluHobby.Items[i].Selected) { user.uHobby += cbluHobby.Items[i].Value; } } user.uEmail = txtuEmail.Text; user.uQQ = txtuQQ.Text; user.uPwd = txtuPhone.Text; user.uImage = imguImage.ImageUrl.Substring(imguImage.ImageUrl.LastIndexOf("/") + 1); user.uRegTime = System.DateTime.Now; } lq.SubmitChanges(); Response.Redirect("UsersManager.aspx"); }
protected void btnAdd_Click(object sender, EventArgs e) { UsersDataContext lq = new UsersDataContext(); Users user = new Users(); user.uName = txtuName.Text; user.uPwd = txtuPwd.Text; user.uRealName = txtuRealName.Text; user.uSex = rbluSex.SelectedValue; user.uAge = Convert.ToInt16(txtuAge.Text); for (int i = 0; i < cbluHobby.Items.Count; i++) { if (cbluHobby.Items[i].Selected) { user.uHobby += cbluHobby.Items[i].Value; } } user.uEmail = txtuEmail.Text; user.uQQ = txtuQQ.Text; user.uPwd = txtuPhone.Text; user.uImage = imguImage.ImageUrl.Substring(imguImage.ImageUrl.LastIndexOf("/") + 1); user.uRegTime = System.DateTime.Now; lq.Users.InsertOnSubmit(user); lq.SubmitChanges(); Response.Redirect("UserManager.aspx"); }
protected void gvUsers_RowDeleting(object sender, GridViewDeleteEventArgs e) { UsersDataContext lq = new UsersDataContext(); var users = from gt in lq.Users where gt.uID == Convert.ToInt32(gvUsers.DataKeys[e.RowIndex].Value) select gt; foreach (Users user in users) { lq.Users.DeleteOnSubmit(user); } lq.SubmitChanges(); Response.Redirect("UsersManager.aspx"); }