0

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>
4

1 に答える 1

0

UpdatePanel を使用しない場合は、GridView でエディターをキャプチャし、Enter キーを押すと、同じ行に更新ボタンを見つけて、次のように送信します。

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 に答える