protected void btnDelete_Command(object sender, CommandEventArgs e) { if (e.CommandName == "DeleteMessage") { SqlConnection conn = null; SqlDataReader reader = null; // instantiate and open connection conn = new SqlConnection(Reference.Constr); conn.Open(); int index = Convert.ToInt32(e.CommandArgument); // Retrieve the row that contains the button // from the Rows collection. GridViewRow row = gvUser.Rows[index]; LinkButton btnButton1 = sender as LinkButton; GridViewRow gvRow1 = (GridViewRow)btnButton1.NamingContainer; //SqlCommand cmdCount = new SqlCommand("select count(*) as total from Advertisement as a inner join Company as c on a.companyID=c.CompanyID where c.CompanyID=@ID", conn); User uObj = new User(); UserManagement uDao = new UserManagement(); Label lb_msgId = (Label)gvRow1.FindControl("lb_UserID"); // string CurrentSession = Session["UserID"].ToString(); uObj = uDao.getUserByID(lb_msgId.Text); string userName = uObj.Name; if (lb_msgId.Text.ToString() == Session["UserID"].ToString()) { deleteFailure.Visible = true; alertSuccess.Visible = false; updateSuccess.Visible = false; createSuccess.Visible = false; labelDelete.Text = "You cannot delete yourself"; } else { deleteFailure.Visible = false; alertSuccess.Visible = true; updateSuccess.Visible = false; createSuccess.Visible = false; msgSuccess.Text = userName + " Has Been Deleted Successfully!"; Boolean insCnt = uDao.deleteQns(lb_msgId.Text); } //VIC: never inform if the delete is successful or not? Database db = new Database(); SqlCommand cmd = new SqlCommand("Select * from [User] WHERE Type != @paraType and Status = 1"); cmd.Parameters.AddWithValue("@paraType", (string)Session["userType"]); DataSet ds = db.getDataSet(cmd); //gvUser.DataSource = ds; gvUser.DataBind(); } }