单击GridViews页脚中的我的按钮时未触发。没有错误,没有代码被执行,它所做的只是刷新,并且页面上的所有内容均与单击按钮之前完全相同。调试甚至无法执行。
按常规声明后面的代码
页面语言=“ vb” AutoEventWireup =“ false” MasterPageFile =“〜/ Site.Master” CodeBehind =“ RetailCompetition.aspx.vb” Inherits =“ Company.Applications.Production.UI.RetailCompetition”
事件
Protected Sub dgvRetailCompetitions_RowCommand(ByVal sender As Object, ByVal e As GridViewCommandEventArgs)
Try
If e.CommandName = "Insert" AndAlso Page.IsValid Then
Dim _refYear As Integer = (ddlYears.SelectedValue.ToString())
Dim _rewardDescription As String = (CType(dgvRetailCompetitions.FooterRow.FindControl("txtRewardsDescription"), TextBox)).Text
Dim _categoryACondition As Integer = (CType(dgvRetailCompetitions.FooterRow.FindControl("txtCatAConditions"), TextBox)).Text
Dim _categoryBCondition As Integer = (CType(dgvRetailCompetitions.FooterRow.FindControl("txtCatBConditions"), TextBox)).Text
Dim _categoryCCondition As Integer = (CType(dgvRetailCompetitions.FooterRow.FindControl("txtCatCConditions"), TextBox)).Text
Company.Applications.Production.BusinessAccess.RetailCompetitionBusinessAccess.InsertNewRetailCompetitionRecord(_refYear,
_rewardDescription,
_categoryACondition,
_categoryBCondition, _categoryCCondition)
End If
Catch ex As Exception
InformationBox.ShowErrorMessage("Failed")
End Try
End Sub
和按钮
<asp:TemplateField HeaderText="Ref. Year" SortExpression="ReferenceYear" ItemStyle-HorizontalAlign="Center">
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("RefYear") %>' />
</ItemTemplate>
<EditItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Eval("RefYear") %>'></asp:Label>
</EditItemTemplate>
<FooterTemplate>
<asp:Button ID="btnInsertRecord" runat="server" CommandName="Insert" Text="Insert Record" ValidationGroup="Insert" CssClass="buttonBlue"/>
</FooterTemplate>
</asp:TemplateField>
有人能看到什么不对吗?
ASPX文件更新
<%@ Page Language="vb" AutoEventWireup="false" MasterPageFile="~/Site.Master" CodeBehind="RetailCompetition.aspx.vb"
Inherits="Company.Applications.ProductionEngine.UI.RetailCompetition" %>
<%@ Register Src="~/GenericControls/UC_GridViewSort.ascx" TagName="SortExtender"
TagPrefix="uc" %>
<%@ Register Src="~/GenericControls/UC_InformationMessageBox.ascx" TagName="InformationBox"
TagPrefix="uc" %>
<%@ Register Src="~/GenericControls/UC_GridFilter.ascx" TagName="GridFilter" TagPrefix="uc" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<asp:UpdatePanel ID="MainContentUpdatePanel" runat="server">
<ContentTemplate>
<h2>
<asp:Label ID="lblTitle" Text="Retail" runat="server" meta:resourcekey="lblTitle" />
</h2>
<br />
<asp:Panel ID="panelRetailCompetitions" runat="server" Width="100%">
<div class="panels" style="padding-top: 0px; padding-bottom: 0px">
<h4 style="font-weight: bold">
<asp:Label ID="lblSectionTitle" runat="server" Text="Competition View" meta:resourceKey="lblSectionTitle" />
</h4>
<div class="panelContents" style="text-align: left;">
<asp:Table ID="tblRetailCompetitions" runat="server" Width="100%" CellSpacing="10">
<asp:TableRow>
<asp:TableCell>
Select Year
<asp:DropDownList ID="ddlYears" runat="server" EnableViewState="true">
<asp:ListItem Enabled="true" Value="-"></asp:ListItem>
<asp:ListItem Text="2018" Value="2018"></asp:ListItem>
<asp:ListItem Text="2019" Value="2019"></asp:ListItem>
<asp:ListItem Text="2020" Value="2020"></asp:ListItem>
</asp:DropDownList>
</asp:TableCell>
</asp:TableRow>
<asp:TableRow>
<asp:TableCell>
<asp:Button ID="btnCopyToSelectedYear" runat="server" Text="Copy To Selected Year"
Width="145px" CssClass="buttonBlue" />
</asp:TableCell>
</asp:TableRow>
<asp:TableRow>
<asp:TableCell>
<uc:GridFilter ID="GridFilter" runat="server" EnableViewState="true" />
</asp:TableCell>
</asp:TableRow>
</asp:Table>
<asp:GridView ID="dgvRetailCompetitions" runat="server" AutoGenerateColumns="False"
CellPadding="5" ForeColor="#333333" GridLines="Horizontal" BorderColor="#00728F"
BorderStyle="Solid" BorderWidth="2px" EmptyDataText="No Competitions Found!"
EmptyDataRowStyle-ForeColor="Red" EmptyDataRowStyle-HorizontalAlign="Center"
Width="100%" HorizontalAlign="Center" ShowHeaderWhenEmpty="True" AllowPaging="True"
PageSize="20" DataKeyNames="RewardDescription" AllowSorting="True" ShowFooter="True">
<AlternatingRowStyle BackColor="White" Width="70%" HorizontalAlign="Center" />
<Columns>
<asp:CommandField ShowEditButton="true" EditText="Edit" UpdateText="Update" CancelText="Cancel" />
<asp:CommandField ShowDeleteButton="true" DeleteText="Delete" />
<asp:TemplateField HeaderText="Ref. Year" SortExpression="ReferenceYear" ItemStyle-HorizontalAlign="Center">
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("RefYear") %>' />
</ItemTemplate>
<EditItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Eval("RefYear") %>'></asp:Label>
</EditItemTemplate>
<FooterTemplate>
<asp:Button ID="btnInsertRecord" runat="server" CommandName="Insert" Text="Insert Record"
ValidationGroup="Insert" CssClass="buttonBlue" />
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Reward Description" SortExpression="RewardDescription">
<ItemTemplate>
<asp:Label ID="lblRewardsDescription" runat="server" Text='<%# Eval("RewardDescription") %>' />
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtRewardsDescription" runat="server" MaxLength="50" Text='<%# Eval("RewardDescription") %>'
Width="200px" />
<asp:CompareValidator ID="txtRewardsDescription_String" runat="server" ControlToValidate="txtRewardsDescription"
Display="Dynamic" ErrorMessage="'Target' must be a string" ForeColor="Red" Operator="DataTypeCheck"
SetFocusOnError="true" Type="String" />
</EditItemTemplate>
<ItemStyle HorizontalAlign="Center" />
<FooterTemplate>
<asp:TextBox ID="txtRewardsDescription" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="rfvRewardsDescription" runat="server" ControlToValidate="txtRewardsDescription"
ErrorMessage="Reward Description Required" Display="Dynamic" ValidationGroup="Insert"></asp:RequiredFieldValidator>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Cat. A Conditions" SortExpression="CategoryA_Conditions">
<ItemTemplate>
<asp:Label ID="Label3" runat="server" Text='<%# Bind("CategoryA_Conditions") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:Label ID="Label3" runat="server" Text='<%# Eval("CategoryA_Conditions") %>'></asp:Label>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtCatAConditions" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="rfvCatAConditions" runat="server" ControlToValidate="txtCatAConditions"
ErrorMessage="Cat. A Conditions Required" Display="Dynamic" ValidationGroup="Insert"></asp:RequiredFieldValidator>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Cat. B Conditions" SortExpression="CategoryB_Conditions">
<ItemTemplate>
<asp:Label ID="Label4" runat="server" Text='<%# Bind("CategoryB_Conditions") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:Label ID="Label4" runat="server" Text='<%# Eval("CategoryB_Conditions") %>'></asp:Label>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtCatBConditions" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="rfvCatBConditions" runat="server" ControlToValidate="txtCatBConditions"
ErrorMessage="Cat. B Conditions Required" Display="Dynamic" ValidationGroup="Insert"></asp:RequiredFieldValidator>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Cat. C Conditions" SortExpression="CategoryC_Conditions">
<ItemTemplate>
<asp:Label ID="Label5" runat="server" Text='<%# Bind("CategoryC_Conditions") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:Label ID="Label5" runat="server" Text='<%# Eval("CategoryC_Conditions") %>'></asp:Label>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtCatCConditions" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="rfvCatCConditions" runat="server" ControlToValidate="txtCatCConditions"
ErrorMessage="Cat. C Conditions Required" Display="Dynamic" ValidationGroup="Insert"></asp:RequiredFieldValidator>
</FooterTemplate>
</asp:TemplateField>
</Columns>
<EditRowStyle BackColor="#4fb3cf" />
<EmptyDataRowStyle ForeColor="Red" HorizontalAlign="Center" />
<FooterStyle BackColor="#FBAD23" Font-Bold="True" ForeColor="White" HorizontalAlign="Center" />
<HeaderStyle BackColor="#FBAD23" Font-Bold="True" ForeColor="Black" />
<PagerStyle BackColor="#FBAD23" Font-Bold="true" ForeColor="Black" HorizontalAlign="Center" />
<RowStyle BackColor="#EFF3FB" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
<SortedAscendingCellStyle BackColor="#F5F7FB" />
<SortedAscendingHeaderStyle BackColor="#6D95E1" />
<SortedDescendingCellStyle BackColor="#E9EBEF" />
<SortedDescendingHeaderStyle BackColor="#4870BE" />
</asp:GridView>
</div>
</div>
<asp:ValidationSummary ID="validationSummary" runat="server" ValidationGroup="Insert"
ForeColor="Red" />
</asp:Panel>
<uc:SortExtender ID="dgvRetailCompetitions_SortExtender" runat="server" EnableViewState="true"
GridViewSortExpression="RewardDescription" GridViewSortDirection="Ascending" />
</ContentTemplate>
</asp:UpdatePanel>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<uc:InformationBox ID="InformationBox" runat="server" EnableViewState="true" />
</ContentTemplate>
</asp:UpdatePanel>
</asp:Content>
答案 0 :(得分:0)
看看之后,我有两个建议给您-
1)检查绑定网格视图的位置-
它应该在里面-!IsPostBack
例如:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
grid.DataBind();
}
}
2)您是否在某处禁用了ViewState?
编辑-已解决问题
在asp:GridView中,需要有一个onrow命令才能在代码背后触发该命令。将此添加到.aspx页
中的asp:gridview标记中 onrowcommand="dgvRetailCompetitions_RowCommand"