【问题标题】:Gridview RowCommand not firing when ButtonField clicked单击 ButtonField 时 Gridview RowCommand 未触发
【发布时间】:2016-08-05 21:51:26
【问题描述】:

火狐:

当 buttonField 被点击时,我检查OnRowCommand,我看到commandName 等于“Activar”,这是正确的。

Chrome 和 IE:

单击按钮时,commandName 等于“选择”,这是不正确的。

我在SelectedIndexChanged 的第一行也有一个断点,并且在 FF 上从未命中,在 Ch 和 IE 上它确实命中,这意味着按钮单击事件没有触发

我在跑步:

  • VS12(最新版本中也出现问题)
  • .NET 框架 4.0

GridView:

<asp:GridView ID="gvNombreEmp" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource10" 
                style="margin-left:auto; margin-right:auto; width:100%" CssClass ="table"
                AllowPaging="True" AllowSorting="True"  BackColor="LightGoldenrodYellow" BorderColor="Tan" BorderWidth="1px"
                CellPadding="2" ForeColor="Black" GridLines="None" OnRowDataBound ="gvNombreEmp_RowDataBound"
                  OnDataBound ="gvNombreEmp_DataBound" OnSelectedIndexChanged ="gvNombreEmp_SelectedIndexChanged" 
                OnPageIndexChanging ="gvNombreEmp_PageIndexChanging" OnRowCommand ="gvNombreEmp_RowCommand">
                <AlternatingRowStyle BackColor="PaleGoldenrod" />

                <Columns>

                     <asp:BoundField DataField="NumeroControl" HeaderText="Número Control" >
                     <HeaderStyle Font-Size="13pt" />
                     <ItemStyle Font-Size="12pt" />
                    </asp:BoundField>

                    <asp:BoundField DataField="NombreEmpresa" HeaderText="Nombre Empresa" >
                     <HeaderStyle Font-Size="13pt" />
                     <ItemStyle Font-Size="12pt" />
                    </asp:BoundField>

                    <asp:BoundField DataField="FC" HeaderText="Fecha Comienzo" >
                     <HeaderStyle Font-Size="13pt" />
                     <ItemStyle Font-Size="12pt" />
                    </asp:BoundField>

                    <asp:BoundField DataField="FE" HeaderText="Fecha Expiración" >
                     <HeaderStyle Font-Size="13pt" />
                     <ItemStyle Font-Size="12pt" />
                    </asp:BoundField>

                    <asp:BoundField DataField="EST" HeaderText="Estatus" >
                     <HeaderStyle Font-Size="13pt" />
                     <ItemStyle Font-Size="12pt" />
                    </asp:BoundField>

                    <asp:ButtonField  CommandName ="Activar" ButtonType="Button" Text ="Desactivar" />

                </Columns>

                <FooterStyle BackColor="Tan" />
                <HeaderStyle BackColor="Tan" Font-Bold="True" />
                <PagerStyle BackColor="Tan" Font-Size ="Large" ForeColor="DarkSlateBlue" Font-Bold ="true"/>
                <SelectedRowStyle BackColor="DarkSlateBlue" ForeColor="GhostWhite" />
                <SortedAscendingCellStyle BackColor="#FAFAE7" />
                <SortedAscendingHeaderStyle BackColor="#DAC09E" />
                <SortedDescendingCellStyle BackColor="#E1DB9C" />
                <SortedDescendingHeaderStyle BackColor="#C2A47B" />
            </asp:GridView>

行命令:

switch(e.CommandName)
{
    case "Activar":

    break;
}

【问题讨论】:

    标签: c# asp.net gridview


    【解决方案1】:

    设法让它适用于 Chrome,但现在它不适用于 FF 和 IE。但这是可以接受的,因为我的客户端只使用 Chrome。

    我所做的是删除 ButtonType 属性,CommandName 等于“Activar”。我只需要确保如果我需要将它实例化为一个变量,我必须确保将其转换为 LinkButton 而不是常规的 Button

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-01-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-11-23
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多