捕获gridview内联编辑中的输入并进行更新

时间:2013-08-16 21:23:40

标签: jquery asp.net gridview

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

如何防止这种情况,当我按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>

1 个答案:

答案 0 :(得分: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函数初始化它。

相关问题和链接: Capturing the Enter key when editing a GridView textbox
Handling the Enter key pressed in a GridView's row edit mode

相关问题