我遇到了问题。我的网页上有Gridview
编辑/更新/取消编辑。
页面工作/渲染,直到我将 OnRowUpdating =“UpdateRow”添加到Gridview
。然后页面根本不呈现。
在调试中,它甚至没有进入页面加载事件。当我从Gridview中取出这个属性(而不触及代码背后的任何代码)时,页面呈现。我一直在谷歌搜索,找不到任何类似的东西。我可以发现它是不会触发/不起作用,但是没有关于页面不呈现的内容。
我的代码如下:
<asp:GridView ID="GridView1" runat="server" CellPadding="4" ForeColor="#333333" GridLines="None"
AutoGenerateColumns="false"
Width="100%"
OnRowEditing="EditRow"
OnRowUpdating="UpdateRow"
OnRowCancelingEdit="CancelEditRow"
DataKeyNames="OnCallID"
AllowPaging="true"
PageSize="50"
OnPageIndexChanging="ChangePage"
OnRowDataBound="gvVehicle_OnRowDataBound"
>
<Columns>
<asp:TemplateField HeaderText="Edit" HeaderStyle-HorizontalAlign="Left" HeaderStyle-Width="25px">
<ItemTemplate>
<asp:LinkButton ID="lnkEdit" runat="server" Text="Edit" CommandName="Edit" />
</ItemTemplate>
<EditItemTemplate>
<asp:LinkButton ID="lnkUpdate" runat="server" Text="Update" CommandName="Update" />
<asp:LinkButton ID="lnkCancel" runat="server" Text="Cancel" CommandName="Cancel" />
</EditItemTemplate>
</asp:TemplateField>
<asp:BoundField HeaderText="OnCallID" DataField="OnCallID" ReadOnly="true" HeaderStyle-HorizontalAlign="Left" HeaderStyle-Width="25px" Visible="false" />
<asp:TemplateField HeaderText="OnCallID" HeaderStyle-HorizontalAlign="Left" HeaderStyle-Width="600px" Visible="false" >
<ItemTemplate><%# Eval("OnCallID")%></ItemTemplate>
<EditItemTemplate>
<asp:Label ID="HDNOnCallID" runat="server" Visible="true" Text='<%# Eval("OnCallID")%>' />
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Team Member Name" HeaderStyle-HorizontalAlign="Left" HeaderStyle-Width="600px" >
<ItemTemplate><%# Eval("TeamMemberName")%></ItemTemplate>
<EditItemTemplate>
<asp:Label ID="LBLUserIDLST" runat="server" Visible="true" Text='<%# Eval("TeamMemberName")%>' />
<!--<asp:ListBox ID="UserIDLST" runat="server" SelectionMode="Single" Visible="true" Width="100" Rows="1"></asp:ListBox> -->
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="On Call Start Date" HeaderStyle-HorizontalAlign="Left" HeaderStyle-Width="600px" >
<ItemTemplate><%# Eval("OnCallStartDate")%></ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="StartDateEditUpdate" runat="server" MaxLength="10" name="StartDateEditUpdate" Width="70" Text='<%# Eval("OnCallStartDate")%>'></asp:TextBox>
<asp:Image id="StartDateEditUpdateCalImg" runat="server" ImageUrl="../Images/CalendarImg.png" ImageAlign="Bottom" />
<ajaxToolkit:CalendarExtender ID="extendStartDateEditUpdate" runat="server" CssClass="datePicker" PopupPosition="TopLeft"
TargetControlID="StartDateEditUpdate" Format="MM/dd/yyyy" PopupButtonID="StartDateEditUpdateCalImg">
</ajaxToolkit:CalendarExtender>
<asp:RequiredFieldValidator ID="validateStartDateEditUpdate"
ControlToValidate="StartDateEditUpdate"
Text="You must Type Something in for Start Date!"
runat="server"
Enabled="true"
CssClass="validatorErrorDisplay"
/>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="On Call Start Time" HeaderStyle-HorizontalAlign="Left" HeaderStyle-Width="600px" >
<ItemTemplate><%# Eval("OnCallStartTime")%></ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="StartTimeEditUpdate" runat="server" MaxLength="10" Width="100" Text='<%# Eval("OnCallStartTime")%>'></asp:TextBox>
<ajaxToolkit:MaskedEditExtender ID="MaskedEditorStartTimeEditUpdate" runat="server"
TargetControlID="StartTimeEditUpdate"
Mask="99:99"
MessageValidatorTip="true"
OnFocusCssClass="MaskedEditFocus"
OnInvalidCssClass="MaskedEditError"
MaskType="Time"
InputDirection="LeftToRight"
ErrorTooltipEnabled="True"
AcceptAMPM="true"
AutoComplete="true"
/>
<ajaxToolkit:MaskedEditValidator ID="MaskedEditorValidatorStartTimeEditUpdate" runat="server"
ControlExtender="MaskedEditorStartTimeEditUpdate"
ControlToValidate="StartTimeEditUpdate"
IsValidEmpty="true"
AcceptAMPM = "true"
InvalidValueMessage="This is not a valid time2"
InvalidValueBlurredMessage="This is not a valid time"
Enabled="true"
TooltipMessage="Must be in Time format HH:MM AM/PM"
ValidationExpression="(0[1-9]|1[0-2]):([0-5][0-9]) (AM|PM|am|pm)"
/>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="On Call End Date" HeaderStyle-HorizontalAlign="Left" HeaderStyle-Width="600px" >
<ItemTemplate><%# Eval("OnCallEndDate")%></ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="EndDateEditUpdate" runat="server" MaxLength="10" name="EndDateEditUpdate" Width="70" Text='<%# Eval("OnCallEndDate")%>'></asp:TextBox>
<asp:Image id="EndDateEditUpdateCalImg" runat="server" ImageUrl="../Images/CalendarImg.png" ImageAlign="Bottom" />
<ajaxToolkit:CalendarExtender ID="extendEditUpdate" runat="server" CssClass="datePicker" PopupPosition="TopLeft"
TargetControlID="EndDateEditUpdate" Format="MM/dd/yyyy" PopupButtonID="EndDateEditUpdateCalImg">
</ajaxToolkit:CalendarExtender>
<asp:RequiredFieldValidator ID="validateEndDateEditUpdate"
ControlToValidate="EndDateEditUpdate"
Text="You must Type Something in for End Date!"
runat="server"
Enabled="true"
CssClass="validatorErrorDisplay"
/>
<asp:CompareValidator ID="CompareStartDateEndDateEditUpdateValidator" Operator="GreaterThanEqual" Type="Date"
ControlToValidate="EndDateEditUpdate" ControlToCompare="StartDateEditUpdate"
ErrorMessage="End Date must be greater then Start Date!" runat="server" BackColor="Red" ForeColor="White" />
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="On Call End Time" HeaderStyle-HorizontalAlign="Left" HeaderStyle-Width="600px" >
<ItemTemplate><%# Eval("OnCallEndTime")%></ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="EndTimeEditUpdate" runat="server" MaxLength="10" Width="100" Text='<%# Eval("OnCallEndTime")%>'></asp:TextBox>
<ajaxToolkit:MaskedEditExtender ID="MaskedEditorEndTimeEditUpdate" runat="server"
TargetControlID="EndTimeEditUpdate"
Mask="99:99"
MessageValidatorTip="true"
OnFocusCssClass="MaskedEditFocus"
OnInvalidCssClass="MaskedEditError"
MaskType="Time"
InputDirection="LeftToRight"
ErrorTooltipEnabled="True"
AcceptAMPM="true"
AutoComplete="true"
/>
<ajaxToolkit:MaskedEditValidator ID="MaskedEditorValidatorEndTimeEditUpdate" runat="server"
ControlExtender="MaskedEditorEndTimeEditUpdate"
ControlToValidate="EndTimeEditUpdate"
IsValidEmpty="true"
AcceptAMPM = "true"
InvalidValueMessage="This is not a valid time2"
InvalidValueBlurredMessage="This is not a valid time"
Enabled="true"
TooltipMessage="Must be in Time format HH:MM AM/PM"
ValidationExpression="(0[1-9]|1[0-2]):([0-5][0-9]) (AM|PM|am|pm)"
/>
</EditItemTemplate>
</asp:TemplateField>
</Columns>
<AlternatingRowStyle BackColor="White" />
<EditRowStyle BackColor="#efefef" />
<FooterStyle BackColor="#F37721" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#F37721" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="#EFF3FB" />
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
<SortedAscendingCellStyle BackColor="#F5F7FB" />
<SortedAscendingHeaderStyle BackColor="#6D95E1" />
<SortedDescendingCellStyle BackColor="#E9EBEF" />
<SortedDescendingHeaderStyle BackColor="#4870BE" />
</asp:GridView>
protected void EditRow(object sender, GridViewEditEventArgs e)
{
// this enables/disables the add new row validation
EnableDisableValidationsAndButtons(false);
GridView1.EditIndex = e.NewEditIndex;
this.PopulateData();
}
protected void CancelEditRow(object sender, GridViewCancelEditEventArgs e)
{
// this enables/disables the add new row validation
EnableDisableValidationsAndButtons(true);
GridView1.EditIndex = -1;
this.PopulateData();
}
protected void UpdateRow(object sender, GridViewUpdatedEventArgs e)
{
//GridViewRow row = (GridViewRow)GridView1.Rows[e.NewEditIndex];
GridViewRow row = (GridViewRow)GridView1.Rows[GridView1.EditIndex];
Label txtOnCallID = (Label)row.FindControl("HDNOnCallID");
String OnCallID = txtOnCallID.Text.ToString();
TextBox txtBoxStartDate = (TextBox)row.FindControl("StartDate");
String StartDate = txtBoxStartDate.Text.ToString();
TextBox txtBoxStartTime = (TextBox)row.FindControl("StartTime");
String StartTime = txtBoxStartTime.Text.ToString();
TextBox txtBoxEndDate = (TextBox)row.FindControl("EndDate");
String EndDate = txtBoxStartDate.Text.ToString();
TextBox txtBoxEndTime = (TextBox)row.FindControl("EndTime");
String EndTime = txtBoxEndTime.Text.ToString();
// do update stuff here
SQL CODE HERE
// run update
//new DatabaseConnection().RSExecute(sCommand);
lblMessage.Text = "Record successfully Updated!";
GridView1.EditIndex = -1;
//this.PopulateData();
// doing a redirect here for the full URL because if you refresh page it adds the record duplicate times
// also some of the form fields are still filled out, this removes them as well
Response.Redirect(Request.Url.AbsoluteUri);
}
答案 0 :(得分:0)
如下所示更改功能的签名并检查。你是GridViewUpdatedEventArgs而不是GridViewUpdateEventArgs的绑定函数
protected void UpdateRow(object sender, GridViewUpdateEventArgs e)
{
}