protected void gvProjects_RowUpdating(object sender, GridViewUpdateEventArgs e) { // Finding the controls from Gridview for the row which is going to update Int32 id = Convert.ToInt32((gvProjects.Rows[e.RowIndex].FindControl("lbl_ID") as Label).Text); String project_name = (gvProjects.Rows[e.RowIndex].FindControl("tb_project") as TextBox).Text; String project_folder = (gvProjects.Rows[e.RowIndex].FindControl("tb_folder") as TextBox).Text; String ftp = (gvProjects.Rows[e.RowIndex].FindControl("tb_ftps") as TextBox).Text; sqlhelper.OpenConnection(); // if it's a new entry - check here for the id given in the table since we can't be sure if the newID variable is still correct if (id == Convert.ToInt32((gvProjects.Rows[gvProjects.Rows.Count - 1].FindControl("lbl_ID") as Label).Text)) { sqlhelper.InsertIntoTable("TrProjects", new KeyValuePair <string, string>("project", project_name), new KeyValuePair <string, string>("folder", project_folder)); } else { // otherwise update it sqlhelper.UpdateTable("TrProjects", "id = " + id, new KeyValuePair <string, string>("project", project_name), new KeyValuePair <string, string>("folder", project_folder)); } // its faster code to delete all targets of that projecs and read the ones given in the list sqlhelper.DeleteRow("TrProjectFTPTargets", "ProjID = " + id); // update ftp target assignment table if (ftp != "") { foreach (string ftpTarget in ftp.Split(',')) { // check if entered number is actually valid number if (int.TryParse(ftpTarget, out int ftpTargetID)) { sqlhelper.InsertIntoTable("TrProjectFTPTargets", new KeyValuePair <string, string>("TargetID", ftpTargetID.ToString()), new KeyValuePair <string, string>("ProjID", id.ToString())); } } } sqlhelper.CloseConnection(); // Setting the EditIndex property to -1 to cancel the Edit mode in Gridview gvProjects.EditIndex = -1; // Call ShowData method for displaying updated data ShowProjectData(); // Update User Data too since the project names could have changed ShowUserData(); UpdateUserPanel.Update(); }
protected void gvUsers_RowUpdating(object sender, GridViewUpdateEventArgs e) { // Finding the controls from Gridview for the row which is going to update String id = (gvUsers.Rows[e.RowIndex].FindControl("lbl_UserID") as Label).Text; String userName = (gvUsers.Rows[e.RowIndex].FindControl("tb_UserName") as TextBox).Text; String userMail = (gvUsers.Rows[e.RowIndex].FindControl("tb_UserMail") as TextBox).Text; String userProjects = (gvUsers.Rows[e.RowIndex].FindControl("tb_Projects") as TextBox).Text; String userLanguage = (gvUsers.Rows[e.RowIndex].FindControl("tb_UserLang") as TextBox).Text; String userDefaultLanguage = (gvUsers.Rows[e.RowIndex].FindControl("tb_UserDefLang") as TextBox).Text; String userSourceLanguage = (gvUsers.Rows[e.RowIndex].FindControl("tb_UserSrcLang") as TextBox).Text; sqlhelper.OpenConnection(); // update user table sqlhelper.UpdateTable("AspNetUsers", "id = '" + id + "'", new KeyValuePair <string, string>("UserName", userName), new KeyValuePair <string, string>("Email", userMail), new KeyValuePair <string, string>("DefaultLanguage", userDefaultLanguage), new KeyValuePair <string, string>("SourceLanguage", userSourceLanguage)); // update language table sqlhelper.UpdateOrInsertIntoTable("TrUserLanguages", new KeyValuePair <string, string>("UserID", id), new KeyValuePair <string, string>("Language", userLanguage)); // update project table // its faster code to delete all projects of that user and readd the ones given in the list, really. sqlhelper.DeleteRow("TrUserProjects", "UserID = '" + id + "'"); if (userProjects != "") { foreach (string proj in userProjects.Split(',')) { string projID = ((projectList.AsEnumerable().Where(r => r.Field <string>("project") == proj.Trim())).FirstOrDefault()["id"]).ToString(); sqlhelper.InsertIntoTable("TrUserProjects", new KeyValuePair <string, string>("UserID", id), new KeyValuePair <string, string>("ProjID", projID)); } } sqlhelper.CloseConnection(); // Setting the EditIndex property to -1 to cancel the Edit mode in Gridview gvUsers.EditIndex = -1; // Update User Data ShowUserData(); UpdateUserPanel.Update(); }