The problem is on most rows, when Select is clicked, the Edit link displays and when Edit is clicked the Update and Cancel links display. However, on some rows the Update link doesn't display (only the Cancel link) when Edit is clicked. It appears to be data related but I can't figure out what in the data is causing the problem.
Here is the code for the RowEditing event:
protected void gvSchedules_RowEditing(object sender, GridViewEditEventArgs e) { Master.resultsMessage = null; Master.showResults = false; try { // Cancel the paging operation if the user attempts to edit another record while the // gridview control is in edit mode. if (gvSchedules.SelectedIndex == -1 || gvSchedules.SelectedIndex != e.NewEditIndex) { // Use the Cancel property to cancel e.Cancel = true; // Display an error message Master.resultsMessage = "You must select the record before trying to edit."; Master.showResults = true; return; } // Cancel the paging operation if the user attempts to edit another record while the // gridview control is in edit mode. if (gvSchedules.EditIndex != -1) { // Use the Cancel property to cancel e.Cancel = true; // Display an error message Master.resultsMessage = "Please finish updating the current record."; Master.showResults = true; return; } // Unhide Select link so Update link will display gvSchedules.Rows[e.NewEditIndex].Cells[0].Controls[0].Visible = true; gvSchedules.Rows[e.NewEditIndex].Cells[0].Controls[1].Visible = true; gvSchedules.Rows[e.NewEditIndex].Cells[0].Controls[2].Visible = true; // get current schedule value Label lblReason = gvSchedules.Rows[e.NewEditIndex].FindControl("lblSchedule") as Label; String currentReason = lblReason.Text; // get currently selected Status value Label label = gvSchedules.Rows[e.NewEditIndex].FindControl("lblActiveFlag") as Label; String currentValue = label.Text; // switch grid to edit mode and re-bind gvSchedules.EditIndex = e.NewEditIndex; gvSchedules.DataSource = dtMasterSchedule; gvSchedules.DataBind(); // grab the DropDownList and find the corresponding option DropDownList ddl = gvSchedules.Rows[e.NewEditIndex].FindControl("ddlStatus") as DropDownList; ListItem item = ddl.Items.FindByValue(currentValue); // set option selected if found if (item != null) item.Selected = true; // Enable Edit Schedule Hours textboxes tbEditMonStart.Enabled = true; tbEditMonEnd.Enabled = true; tbEditMonHours.Enabled = true; tbEditTueStart.Enabled = true; tbEditTueEnd.Enabled = true; tbEditTueHours.Enabled = true; tbEditWedStart.Enabled = true; tbEditWedEnd.Enabled = true; tbEditWedHours.Enabled = true; tbEditThuStart.Enabled = true; tbEditThuEnd.Enabled = true; tbEditThuHours.Enabled = true; tbEditFriStart.Enabled = true; tbEditFriEnd.Enabled = true; tbEditFriHours.Enabled = true; tbEditSatStart.Enabled = true; tbEditSatEnd.Enabled = true; tbEditSatHours.Enabled = true; tbEditSunStart.Enabled = true; tbEditSunEnd.Enabled = true; tbEditSunHours.Enabled = true; // Hide page row// gvSchedules.PagerSettings.Visible = false; // Update Schedule List Panel udpScheduleList.Update(); udpEditSchedules.Update(); } catch (Exception exp) { string host = HttpContext.Current.Request.Url.Host.ToLower(); if (!host.Contains("d-conn")) { IntranetSupport iSupport = new IntranetSupport(); string returnvalue = ""; returnvalue = iSupport.ReportError(exp, Convert.ToInt32(Session["EmployeeProfileID"]), HttpContext.Current.Request.Url.AbsolutePath, "", ""); if (returnvalue != "") Response.Redirect(returnvalue); } else { throw exp; } } }
Any help is pointing me in the right direction for solving this is greatly appreciated!
ASP.NET
Last Comment
dyarosh
8/22/2022 - Mon
Bob Learned
What is this code used for?
// Unhide Select link so Update link will display gvSchedules.Rows[e.NewEditIndex].Cells[0].Controls[0].Visible = true; gvSchedules.Rows[e.NewEditIndex].Cells[0].Controls[1].Visible = true; gvSchedules.Rows[e.NewEditIndex].Cells[0].Controls[2].Visible = true;
Open in new window