按Enter键时触发事件

时间:2014-07-29 07:10:18

标签: c# asp.net

如果用户触发listview的编辑事件并且如果用户当前没有编辑列表视图,是否有办法触发listview的更新事件,按Enter按钮将触发某个按钮的click事件。

ASPX

   <form runat="server">
    <div class="row">
        <div class="form-group">
            <label class="col-md-3 control-label">Label:</label>
            <div class="col-md-8">
                <asp:TextBox ID="TextBox1" runat="server" />
            </div>
        </div>
    </div>
    <div class="row">
        <table class="table table-bordered table-hover table-responsive">
            <thead>
                <tr>
                    <th>Product ID</th>
                    <th>Product Name</th>
                    <th>Quantity</th>
                    <th></th>
                </tr>    
            </thead>
            <tbody>
                <asp:ListView ID="ListView1" runat="server"
                    onitemcanceling="ListView1_ItemCanceling" 
                    onitemediting="ListView1_ItemEditing" 
                    onitemupdating="ListView1_ItemUpdating" >
                    <ItemTemplate>
                        <tr>
                            <td><%# Eval("ProductID") %></td>
                            <td><%# Eval("ProductName") %></td>
                            <td><%# Eval("Quantity") %></td>
                            <td>
                                <asp:LinkButton ID="lnkDelete" runat="server" 
                                class="glyphicon glyphicon-remove" CommandName="Delete" />
                            </td>
                        </tr>
                    </ItemTemplate>
                    <EmptyDataTemplate>
                        <tr>
                            <td colspan="4"><h5><center>Select a product first then click "Add Product".</center></h5></td>
                        </tr>
                    </EmptyDataTemplate>
                </asp:ListView>
            </tbody>
        </table>
    </div>
    <div class="row">
        <asp:Button ID="button1" runat="server" />

             

1 个答案:

答案 0 :(得分:1)

使用asp:Panel控件DefaultButton属性设置默认按钮单击事件

 <asp:Panel ID="pnlMain" runat="server" DefaultButton="btnSend" Width="500px">
 .
 .
 .
   <asp:Button ID="btnSend" runat="server" Text="Save" CssClass="button" OnClick="btnSend_Click" />

 </asp:Panel>