protected void grvCommand_RowCommand(object sender, GridViewCommandEventArgs e) { TestOnlineDataContext db = new TestOnlineDataContext(); //Xóa 1 hàng trong gridview if (e.CommandName == "Delete") { tblCommand doc = db.tblCommands.SingleOrDefault(d => d.CommandID.ToString().Trim() == e.CommandArgument.ToString().Trim()); if (doc != null) { db.tblCommands.DeleteOnSubmit(doc); db.SubmitChanges(); LoadGridview(); lblThongBao.Visible = true; lblThongBao.Text = "Bạn đã xóa thành công"; } } }
protected void btnSend_Click1(object sender, EventArgs e) { TestOnlineDataContext db = new TestOnlineDataContext(); if (txtContent.Text != "") { tblCommand tbl = new tblCommand(); tbl.CommandName = txtContent.Text; tbl.StudentID = Session.Contents["AcountID"].ToString(); tbl.CreateDate = DateTime.Now; db.tblCommands.InsertOnSubmit(tbl); db.SubmitChanges(); lblThongBao.Text = "Bạn đã gửi thành công"; lblThongBao.Text = ""; LoadComment(); } }
protected void btnDeleteAll_Click(object sender, EventArgs e) { int record = 0; TestOnlineDataContext db = new TestOnlineDataContext(); foreach (GridViewRow row in grvCommand.Rows) { CheckBox chk = (CheckBox)row.FindControl("chkSelect"); if (chk != null) { if (chk.Checked) { LinkButton link = (LinkButton)row.FindControl("btnXoa"); tblCommand at = db.tblCommands.SingleOrDefault(c => c.CommandID.ToString() == link.CommandArgument.ToString()); if (at != null) { // delete file when xoa db.tblCommands.DeleteOnSubmit(at); db.SubmitChanges(); record++; } } } } if (record > 0) { LoadGridview(); // when will announciment lblThongBao.Text = "Bạn vừa xóa thành công " + record.ToString() + " bản ghi!"; lblThongBao.Visible = true; } else { lblThongBao.Text = "Không có bản ghi nào được chọn !"; lblThongBao.Visible = true; } }