我有一个将 rowCommand 设置为其中一列的 gridview。一切正常,但我在 gridview 中的每一行都遇到了这个奇怪的错误。RowCommand 块不执行。除最后一行外,所有其他行都有效。如果我对网格视图进行排序并且最后一行位于顶部,则它可以正常工作,但是任何行都位于底部,再次无法正常工作。
<asp:GridView id="gvSchedules" runat="server" AutoGenerateColumns="False"
DataSourceID="odsSchedules" AllowPaging="True" AllowSorting="True" EmptyDataText="gvSchedules"
OnRowCommand="gvSchedules_RowCommand" CssSelectorClass="NormalGridView"
EnableViewState="false">
<Columns>
<asp:TemplateField SortExpression="ScheduleName" HeaderText="gvSchedulesName">
<ItemStyle Width="100%"></ItemStyle>
<HeaderStyle Wrap="false" />
<ItemTemplate>
<asp:hyperlink id="lnkEdit" runat="server" NavigateUrl='<%# EditUrl("ScheduleID", Eval("ScheduleID").ToString(), "edit", "SpaceID=" + PanelSecurity.PackageId) %>'>
<%# PortalAntiXSS.Encode((string)Eval("ScheduleName")) %>
</asp:hyperlink>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField SortExpression="ScheduleTypeID" HeaderText="gvSchedulesType"
ItemStyle-Wrap="false" HeaderStyle-Wrap="false">
<ItemTemplate>
<%# GetSharedLocalizedString("ScheduleType." + Eval("ScheduleTypeID").ToString()) %>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="NextRun" SortExpression="NextRun" HeaderText="gvSchedulesNextRun"
ItemStyle-Wrap="false" HeaderStyle-Wrap="false"></asp:BoundField>
<asp:BoundField DataField="LastRun" SortExpression="LastRun" HeaderText="gvSchedulesLastRun"
ItemStyle-Wrap="false" HeaderStyle-Wrap="false"></asp:BoundField>
<asp:TemplateField HeaderText="gvSchedulesStatus" ItemStyle-Wrap="false">
<ItemTemplate>
<asp:ImageButton ID="cmdStart" runat="server" ToolTip="Start" SkinID="StartMedium" Visible='<%# !IsScheduleActive((int)Eval("StatusID")) %>'
CommandName="start" CommandArgument='<%# Eval("ScheduleID") %>' />
<asp:ImageButton ID="cmdStop" runat="server" ToolTip="Stop" SkinID="StopMedium" Visible='<%# IsScheduleActive((int)Eval("StatusID")) %>'
CommandName="stop" CommandArgument='<%# Eval("ScheduleID") %>' />
<%# GetScheduleStatus((int)Eval("StatusID")) %>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="gvSchedulesResult" HeaderStyle-Wrap="false" ItemStyle-Width="150px">
<ItemTemplate>
<%# GetAuditLogRecordSeverityName((int)Eval("LastResult"))%>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField SortExpression="PackageName" HeaderText="gvSchedulesSpace">
<ItemStyle Wrap="False"></ItemStyle>
<ItemTemplate>
<asp:hyperlink id="lnkSpace" runat="server"
NavigateUrl='<%# GetSpaceHomePageUrl((int)Eval("PackageID")) %>'>
<%# Eval("PackageName") %>
</asp:hyperlink>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField SortExpression="Username" HeaderText="gvSchedulesUser">
<ItemStyle Wrap="False"></ItemStyle>
<ItemTemplate>
<asp:hyperlink id="lnkUser" runat="server"
NavigateUrl='<%# GetUserHomePageUrl((int)Eval("UserID")) %>'>
<%# Eval("Username") %>
</asp:hyperlink>
</ItemTemplate>
<HeaderStyle Wrap="False" />
</asp:TemplateField>
</Columns>
</asp:GridView>
<div class="GridFooter">
<asp:Label ID="lblScheduledTasks" runat="server" meta:resourcekey="lblScheduledTasks" Text="Scheduled Tasks:"></asp:Label>
<uc4:Quota ID="quotaTasks" runat="server" QuotaName="OS.ScheduledTasks" />
</div>
<asp:ObjectDataSource ID="odsSchedules" runat="server" EnablePaging="True" SelectCountMethod="GetSchedulesPagedCount"
SelectMethod="GetSchedulesPaged" SortParameterName="sortColumn" TypeName="WebsitePanel.Portal.SchedulesHelper" OnSelected="odsSchedules_Selected">
<SelectParameters>
<asp:ControlParameter ControlID="chkRecursive" Name="recursive" PropertyName="Checked" />
<asp:ControlParameter ControlID="searchBox" Name="filterColumn" PropertyName="FilterColumn" />
<asp:ControlParameter ControlID="searchBox" Name="filterValue" PropertyName="FilterValue" />
</SelectParameters>
</asp:ObjectDataSource>
和我的服务器端代码
protected void Page_Load(object sender, EventArgs e)
{
Response.Write("zarejdame stranitsata <br />");
//BindServerTime();
// set display preferences
gvSchedules.PageSize = UsersHelper.GetDisplayItemsPerPage();
if (!IsPostBack)
{
chkRecursive.Visible = (PanelSecurity.EffectiveUser.Role != UserRole.User);
// toggle controls
//btnAddItem.Enabled = PackagesHelper.CheckGroupQuotaEnabled(
// PanelSecurity.PackageId, ResourceGroups.Statistics, Quotas.STATS_SITES);
searchBox.AddCriteria("ScheduleName", GetLocalizedString("Text.ScheduleName"));
searchBox.AddCriteria("Username", GetLocalizedString("Text.Username"));
searchBox.AddCriteria("FullName", GetLocalizedString("Text.FullName"));
searchBox.AddCriteria("Email", GetLocalizedString("Text.Email"));
bool isUser = PanelSecurity.SelectedUser.Role == UserRole.User;
gvSchedules.Columns[gvSchedules.Columns.Count - 1].Visible = !isUser;
gvSchedules.Columns[gvSchedules.Columns.Count - 2].Visible = !isUser;
Response.Write("page load za parvi pat<br />");
}
Response.Write("krai na page load<br />");
}
protected void odsSchedules_Selected(object sender, ObjectDataSourceStatusEventArgs e)
{
if (e.Exception != null)
{
ProcessException(e.Exception);
e.ExceptionHandled = true;
}
}
protected void gvSchedules_RowCommand(object sender, GridViewCommandEventArgs e)
{
Response.Write("1111");
Response.Write("aaaa " + e.CommandArgument + "<br />");
int scheduleId = Utils.ParseInt(e.CommandArgument.ToString(), 0);
if (e.CommandName == "start")
{
Response.Write("start schedule<br />");
try
{
int result = ES.Services.Scheduler.StartSchedule(scheduleId);
if (result < 0)
{
ShowResultMessage(result);
return;
}
}
catch (Exception ex)
{
ShowErrorMessage("SCHEDULE_START_TASK", ex);
return;
}
}
else if (e.CommandName == "stop")
{
try
{
int result = ES.Services.Scheduler.StopSchedule(scheduleId);
if (result < 0)
{
ShowResultMessage(result);
return;
}
}
catch (Exception ex)
{
ShowErrorMessage("SCHEDULE_STOP_TASK", ex);
return;
}
}
// rebind grid
gvSchedules.DataBind();
}
我的 PageLoad 中没有任何内容。通过调试,我可以看到输入触发了最后一行的回发,它到达了页面加载,但从未到达 rowCommand 代码块。Response.Write("1111"); 永远不会出现。任何想法都会有所帮助。