问题中的pressing更新的GridView行中输入 [英] Problem updating Gridview row by pressing Enter

查看:136
本文介绍了问题中的pressing更新的GridView行中输入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用的ImageButton作为更新按钮,一个gridview。当用户编辑一行,我想用户可以更新由pressing行输入。我遇到的问题是,虽然RowCommand事件被触发时,CommandName的仍是编辑而不是更新
 所以我的更新code永远不会被执行。我所做的是挂钩一些JavaScript在处理的RowDataBound文本框:

I have a gridview that uses an imagebutton as an update button. When the user edits a row I would like the user to be able to update the row by pressing Enter. The problem I'm having is that though the RowCommand event is fired, the CommandName is still "Edit" instead of "Update so my update code never gets executed. What I've done is hook up some javascript to the textbox in the RowDataBound handler:

 Protected Sub uxShoppingCart_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs)
        If e.Row.RowType = DataControlRowType.DataRow Then
            Dim gvr As GridViewRow = DirectCast(e.Row, GridViewRow)
            If (e.Row.RowState And DataControlRowState.Edit) = DataControlRowState.Edit Then
                Dim edit_Qty As TextBox = DirectCast(gvr.FindControl("edit_Qty"), TextBox)
                Dim uxUpdateButton As ImageButton = DirectCast(gvr.FindControl("uxUpdateButton"), ImageButton)
                uxQty.Attributes.Add("onkeypress", "return clickButton(event,'" & uxUpdateButton.ClientID & "')")
                edit_Qty.Focus()
            End If
        End If
    End Sub

JavaScript函数如下:

The javascript function is as follows:

function clickButton(e, buttonid) {
    var bt = document.getElementById(buttonid);
    if (typeof bt == 'object') {
        if (navigator.appName.indexOf("Netscape") > (-1)) {
            if (e.keyCode == 13) {
                bt.click();
                return false;
            }
        }
        if (navigator.appName.indexOf("Microsoft Internet Explorer") > (-1)) {
            if (event.keyCode == 13) {
                bt.click();
                return false;
            }
        }
    }
}

和这里的按钮声明

<EditItemTemplate>
    <span style="display: inline; white-space: nowrap;">
    	<asp:ImageButton ID="uxUpdateButton" runat="server" CausesValidation="True" CommandName="Update" ImageUrl="~/images/icons/accept.png" AlternateText="Update" ToolTip="Update"></asp:ImageButton>
    	<asp:ImageButton ID="uxCancelButton" runat="server" CausesValidation="False" CommandName="Cancel" ImageUrl="~/images/icons/cancel.png" AlternateText="Cancel" ToolTip="Cancel"></asp:ImageButton>
    </span>
</EditItemTemplate>

如果我点击使用CommandName的更新被预期通过鼠标更新按钮,只是没有当我通过javascript点击它。任何帮助将是AP preciated。

If I click the update button using the mouse the CommandName "Update" gets passed as expected, just not when I "click" it via javascript. Any help would be appreciated.

推荐答案

我终于能够回到这个用全新的眼光。原来,问题是我使用同场ajaxcontroltoolkit的maskededitextender。我猜扩展器拦截安其preSS事件。

I was finally able to return to this with a fresh eye. It turns out the problem is the maskededitextender from the ajaxcontroltoolkit that I'm using with the field. I'm guessing the extender is intercepting the onkeypress event.

下面是我的解决方案。我摆脱了maskededitextender和使用直接的JavaScript,而不是和我分配javascript函数的文本框的安其preSS事件:

Here's my solution. I got rid of the maskededitextender and used straight javascript instead and assigned my javascript function to the textbox's onkeypress event:

AddQty.Attributes.Add("onkeypress", "return NumericInput(event,'" & uxAddButton.ClientID & "')")

和这里的JavaScript的:

And here's the javascript:

<script type="text/javascript">
    function NumericInput(e, id) {
        if (!e) e = window.event;
        if (e.keyCode > 31 && (e.keyCode < 48 || e.keyCode > 57)) {
            return false;
        } else {
            if (e.keyCode == 13) {
                var bt = document.getElementById(id);
                if (bt != null) {
                    bt.click();
                    return false;
                }
            }
        }
    } 
 </script>

这篇关于问题中的pressing更新的GridView行中输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆