0

当我在 GridView 上使用内联编辑并开始编辑一行时,当我在任何文本编辑器上按 enter 时,不是更新该行,而是取消它,关闭更新并返回。

我怎样才能防止这种情况发生,当我按下回车键使用jQuery在线提交更新时。

<asp:GridView ID="gvLista" runat="server" AllowPaging="True"  AllowSorting="True" AutoGenerateColumns="False" DataSourceID="SqlDataSource1" >
    <Columns>
        <asp:CommandField ShowDeleteButton="true" ShowEditButton="true" >

        <-- rest of BoundField with editors or other data -->
        <asp:BoundField DataField="Name" />         
        </asp:CommandField>
    </Columns>
</asp:GridView>
4

1 回答 1

0

如果我们不使用 UpdatePanel,那么我们会在 GridView 上捕获编辑器,然后在按下回车键时,我们会在同一行找到更新按钮并提交它,如下所示:

jQuery(document).ready(function() {         
    // capture the open editors inside the GridView (if any)
    jQuery('#<%= gvLista.ClientID %> :input[type=text]').keydown(function (e) 
    {
        // on keydown if is press the enter
        if (e.keyCode == 13) 
        {
            // not let him submit the form on any other button
            e.preventDefault();
            // but find on the same line, the Update Button, and submit that one
            jQuery(this).parents("tr").find("input[value=Update]").click();
        }
    });
});

如果我们使用 UpdatePanel,想法是一样的,但是我们必须使用 UpdatePanel 函数来初始化,每次 UpdatePanel 更新它们的内容。

相关问题和链接: 在编辑 GridView 文本框时捕获 Enter 键
处理在 GridView 的行编辑模式下按下的 Enter 键

于 2013-08-16T21:23:39.943 回答