ASP.net-Gridview文本框输入按钮回发

时间:2019-01-03 17:06:35

标签: asp.net

我有一个带有文本框的GridView,当用户更改该框中的文本时,我希望他们能够按Enter键并回发并更新他们在GridView中该文本框中所做的更改。

我不知道该怎么做?

谢谢, 标记

1 个答案:

答案 0 :(得分:0)

您需要使用一些JavaScript代码来做到这一点-在页面部分。这是我使用的(jQuery)

$(document).ready(function(){
    // capture the editors
    var AllEditors = jQuery('#<%= gvGridViewID.ClientID %> :input[type=text]');

    AllEditors.keydown(function (e) {
        if (e.keyCode == 13) 
        {
            e.preventDefault();
            // the [value=Update] is the default value to Update control of GridView
            jQuery(this).parents("tr").find("input[value=Update]").click();
        }
    });
});

如果将其保存在UpdatePanel中,则每次UpatePanel触发时都需要对其进行初始化。如果您将它放在自定义控件中,则需要在函数名称上添加额外的变量,以免发生冲突。

相关问题