dyarosh
asked on
Update Link doesn't always display in GridView when Edit link is clicked
I have a GridView in asp.net (c#) that has the following definition:
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:
Any help is pointing me in the right direction for solving this is greatly appreciated!
<asp:GridView ID="gvSchedules" runat="server" CellPadding="5" OnRowCreated="gvSchedules_RowCreated"
OnPageIndexChanging="gvSchedules_PageIndexChanging" OnRowCancelingEdit="gvSchedules_RowCancelingEdit"
OnRowEditing="gvSchedules_RowEditing" OnRowUpdating="gvSchedules_RowUpdating" OnSelectedIndexChanged="gvSchedules_SelectedIndexChanged"
AlternatingRowStyle-BackColor="#0099CC" AlternatingRowStyle-BorderColor="Black"
AlternatingRowStyle-BorderStyle="Solid" AlternatingRowStyle-ForeColor="White"
AlternatingRowStyle-HorizontalAlign="Left" AlternatingRowStyle-VerticalAlign="Middle"
BorderStyle="Solid" HeaderStyle-BackColor="Silver" BorderColor="Black"
HeaderStyle-BorderColor="Black" HeaderStyle-BorderStyle="Solid"
HeaderStyle-HorizontalAlign="Center" HeaderStyle-VerticalAlign="Middle"
HorizontalAlign="Left" RowStyle-BorderColor="Black" RowStyle-BorderStyle="Solid"
RowStyle-HorizontalAlign="Left" RowStyle-VerticalAlign="Middle"
AutoGenerateColumns="False"
EmptyDataText="No Schedules Found" AllowPaging="True" AutoGenerateSelectButton="True" AutoGenerateEditButton="True"
SelectedRowStyle-BorderColor="Red" SelectedRowStyle-BorderStyle="Solid" SelectedRowStyle-BackColor="#993399">
<AlternatingRowStyle HorizontalAlign="Left" VerticalAlign="Middle" BackColor="#0099CC" BorderColor="Black"
BorderStyle="Solid" ForeColor="White"></AlternatingRowStyle>
<HeaderStyle HorizontalAlign="Center" VerticalAlign="Middle" BackColor="Silver" BorderColor="Black"
BorderStyle="Solid"></HeaderStyle>
<RowStyle HorizontalAlign="Left" VerticalAlign="Middle" BorderColor="Black" BorderStyle="Solid"></RowStyle>
<Columns>
<asp:BoundField DataField="MasterScheduleID" HeaderText="Schedule ID" ReadOnly="true" />
<asp:BoundField DataField="DivisionID" HeaderText="Division ID" ReadOnly="true" />
<asp:BoundField DataField="Division" HeaderText="Division" ReadOnly="true" />
<asp:TemplateField HeaderText="Active">
<EditItemTemplate>
<asp:DropDownList ID="ddlStatus" runat="server">
<asp:ListItem Value="Y">ACTIVE</asp:ListItem>
<asp:ListItem Value="N">INACTIVE</asp:ListItem>
</asp:DropDownList>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="lblActiveFlag" runat="server" Text='<%# Bind("ActiveStatusFlag") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Schedule">
<EditItemTemplate>
<asp:TextBox ID="tbEdit" runat="server" ToolTip="Schedule" Text='<%# Bind("Description") %>'
CssClass="ScheduleTextFormat" MaxLength="100"></asp:TextBox>
<asp:RequiredFieldValidator ID="tbScheduleRequiredFieldValidator2" runat="server"
ErrorMessage="Schedule is required" BackColor="Red" Font-Bold="True" ForeColor="White"
ControlToValidate="tbEdit" Display="Dynamic" validationgroup="Info"
Text="*"></asp:RequiredFieldValidator>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="lblSchedule" runat="server" Text='<%# Bind("Description") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="MonStartTime" HeaderText="Mon Start Time" ReadOnly="true" />
<asp:BoundField DataField="MonEndTime" HeaderText="Mon End Time" ReadOnly="true" />
<asp:BoundField DataField="MonHours" HeaderText="Mon Hours" ReadOnly="true" />
<asp:BoundField DataField="TueStartTime" HeaderText="Tue Start Time" ReadOnly="true" />
<asp:BoundField DataField="TueEndTime" HeaderText="Tue End Time" ReadOnly="true" />
<asp:BoundField DataField="TueHours" HeaderText="Tue Hours" ReadOnly="true" />
<asp:BoundField DataField="WedStartTime" HeaderText="Wed Start Time" ReadOnly="true" />
<asp:BoundField DataField="WedEndTime" HeaderText="Wed End Time" ReadOnly="true" />
<asp:BoundField DataField="WedHours" HeaderText="Wed Hours" ReadOnly="true" />
<asp:BoundField DataField="ThuStartTime" HeaderText="Thu Start Time" ReadOnly="true" />
<asp:BoundField DataField="ThuEndTime" HeaderText="Thu End Time" ReadOnly="true" />
<asp:BoundField DataField="ThuHours" HeaderText="Thu Hours" ReadOnly="true" />
<asp:BoundField DataField="FriStartTime" HeaderText="Fri Start Time" ReadOnly="true" />
<asp:BoundField DataField="FriEndTime" HeaderText="Fri End Time" ReadOnly="true" />
<asp:BoundField DataField="FriHours" HeaderText="Fri Hours" ReadOnly="true" />
<asp:BoundField DataField="SatStartTime" HeaderText="Sat Start Time" ReadOnly="true" />
<asp:BoundField DataField="SatEndTime" HeaderText="Sat End Time" ReadOnly="true" />
<asp:BoundField DataField="SatHours" HeaderText="Sat Hours" ReadOnly="true" />
<asp:BoundField DataField="SunStartTime" HeaderText="Sun Start Time" ReadOnly="true" />
<asp:BoundField DataField="SunEndTime" HeaderText="Sun End Time" ReadOnly="true" />
<asp:BoundField DataField="SunHours" HeaderText="Sun Hours" ReadOnly="true" />
</Columns>
</asp:GridView>
</ContentTemplate>
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!
ASKER
That code was used in an attempt to display the Update and Cancel links.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you.
Open in new window