c# - 带有 EditItemTemplate 的面板 DefaultButton 和 GridView 控件

标签 c# asp.net gridview panel defaultbutton

我在一个页面上有一个 GridView 控件,它的面板有一个 DefaultButton。当用户编辑一行时,我试图让“更新”按钮与 Enter 键一起使用。它适用于鼠标。当我单击“更新”时,该行将恢复为查看模式并显示更新后的值。

当 GridView 在 Panel 中时,当我按下 Enter 时,Panel 的默认按钮(提交页面)触发,甚至在处理 RowCommand 之前,并且更新丢失。

当 GridView 不在面板中时,面板中其他一些看似随机的按钮会触发,但不会触发我行的 EditItemTemplate 中的“更新”按钮。具体来说,页面上有一个 CalendarExtender,扩展器的弹出按钮会触发。完全不是我想要的。

我怎样才能让它正常运行?

这是我的标记代码的结构:

<asp:Panel ID="Panel1" runat="server" DefaultButton="btnSubmit">

    <!--Form with controls-->

    <asp:ImageButton ID="btnWSPODateCal" runat="server" />
    <!--this button fires when I press enter while editing a grid row:-->
    <ajaxToolkit:CalendarExtender ID="CalendarExtender1" runat="server" 
    TargetControlID="tbPODate" PopupButtonID="btnWSPODateCal" />

    <!--more controls-->

    <div class="button_row">
        <asp:ImageButton ID="btnCancel" runat="server" />
        <asp:ImageButton ID="btnSubmit" OnClick="btnSubmit_Click" />
    </div>
</asp:Panel>
<asp:GridView runat="server">
    <Columns>
        <asp:TemplateField>
            <EditItemTemplate>
                <asp:ImageButton CommandName="MyUpdate" 
                    ID="btnSubmitRow" runat="server"  
                    CommandArgument="<%# ((GridViewRow) Container).DataItemIndex %>" /> 

最佳答案

试一试。这只是一个猜测。

<asp:GridView runat="server">
<Columns>
    <asp:TemplateField>
        <EditItemTemplate>
            <asp:Panel ID="Panel2" DefaultButton="btnSubmitRow" runat="server">
                <asp:ImageButton CommandName="MyUpdate" 
                    ID="btnSubmitRow" runat="server"  
                    CommandArgument="<%# ((GridViewRow) Container).DataItemIndex %>" />
            </asp:Panel>  

您可能必须在 GridView 的每一列中放置一个面板。唯一可能出现问题的是面板能够“找到”GridViewRow 中的按钮。

你也试过吗?

<asp:Panel ID="Panel2" DefaultButton="btnSubmitRow" runat="server">
    <asp:GridView runat="server">
        <Columns>
        <asp:TemplateField>
            <EditItemTemplate>
                <asp:ImageButton CommandName="MyUpdate" 
                    ID="btnSubmitRow" runat="server"  
                    CommandArgument="<%# ((GridViewRow) Container).DataItemIndex %>" />
...
    </asp:GridView>
</asp:Panel>

关于c# - 带有 EditItemTemplate 的面板 DefaultButton 和 GridView 控件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2268520/

相关文章:

c# - VS2010 : Warning on add project reference to Silverlight project from . 网络项目

c# - 如何在Web服务器上获取用户的IP地址?

c# - 从 Gridview 的 BoundField 访问数据

ASP.NET 嵌套 GridView,DataItem 在子 GridView 的 RowDataBound 事件中返回 null

c# - 在 asp.net 中处理动态生成的控件

c# - SQLite 的 .NET Framework 数据提供程序发生意外错误

c# - 在 C# 中使用 CoreNLP 时出现 SLF4J 错误

c# - 如何在 asp.net 页面中的页面启动时初始化对象

c# - 在 gridview 中使用 OnSelectChange 打印到标签

c# - 如何从 GridView 中删除重复数据?