1

リストビュー内にいくつかのドロップダウン リストがある ASP.NET ページがあります。フォームの一番下に送信ボタンがあります。

ユーザーが「Enter」キーを押すたびに、送信ボタンを押してください。パネルの DefaultButton 属性を使用して他のフォームでこれを実行しましたが、パネルにテキストボックスとボタンがありました。

ここでは defaultbutton プロパティが送信ボタンをトリガーしていません。フォーカスがパネルにないためだと思います。

ただし、パネルにすべての要素を含めると、これも機能しないようです。これは、html のテーブル レイアウト要素が原因だと思います。

では、ユーザーがキーボードの「Enter」を押したときに送信ボタンを押すだけの答えは何ですか?

<table cellpadding="3" cellspacing="1" border="0" width="100%">
    <tr>
        <td align="center" width="100%" class="tableCaptionLabel" colspan="2">
        Asset Search by Photo
        </td>
    </tr>
    <tr valign="top">
        <td colspan="2">



        <asp:ListView ID="lvQuery" runat="server" >
            <LayoutTemplate>
            <asp:Placeholder
            id="groupPlaceholder"
            runat="server" />
            </LayoutTemplate>
            <GroupTemplate>
            <div>
            <asp:Placeholder
            id="itemPlaceholder"
            runat="server" />
            </div>
            </GroupTemplate>
            <ItemTemplate>
            <asp:DropDownList ID="tagname" runat="server" DataSourceID="sqldsTagList" SelectedValue='<%# Bind("Tagname") %>'
                    DataTextField="TagDesc" DataValueField="TagDesc"  AppendDataBoundItems ="true" AutoPostBack="true" OnSelectedIndexChanged="lstTagname_SelectedIndexChanged">
                    <asp:ListItem Text="All" Value="All" />
            </asp:DropDownList>

               <asp:DropDownList ID="Operation" runat="server" SelectedValue='<%# Bind("Operation") %>' AutoPostBack="true" OnSelectedIndexChanged="lstOperation_SelectedIndexChanged">
                    <asp:ListItem Text="Equals" Value="Equals" Selected="True"/>
                    <asp:ListItem Text="Like" Value="Like"  />
               </asp:DropDownList>

            <asp:TextBox ID="TagValue" runat="server" Text='<%# Bind("TagValue") %>' Width="75%"></asp:TextBox>

            <asp:DropDownList ID="ddlAlphabet" runat="server" Visible="false" AutoPostBack="true" OnSelectedIndexChanged="lstAlphabet_SelectedIndexChanged">
                <asp:ListItem Text="A" Value="A" Selected="True"/>
                <asp:ListItem Text="B" Value="B"  />
                <asp:ListItem Text="C" Value="C"  />
                <asp:ListItem Text="D" Value="D"  />
                <asp:ListItem Text="E" Value="E"  />
                <asp:ListItem Text="F" Value="F"  />
                <asp:ListItem Text="G" Value="G"  />
                <asp:ListItem Text="H" Value="H"  />
                <asp:ListItem Text="I" Value="I"  />
                <asp:ListItem Text="J" Value="J"  />
                <asp:ListItem Text="K" Value="K"  />
                <asp:ListItem Text="L" Value="L"  />
                <asp:ListItem Text="M" Value="M"  />
                <asp:ListItem Text="N" Value="N"  />
                <asp:ListItem Text="O" Value="O"  />
                <asp:ListItem Text="P" Value="P"  />
                <asp:ListItem Text="Q" Value="Q"  />
                <asp:ListItem Text="R" Value="R"  />
                <asp:ListItem Text="S" Value="S"  />
                <asp:ListItem Text="T" Value="T"  />
                <asp:ListItem Text="U" Value="U"  />
                <asp:ListItem Text="V" Value="V"  />
                <asp:ListItem Text="W" Value="W"  />
                <asp:ListItem Text="X" Value="X"  />
                <asp:ListItem Text="Y" Value="Y"  />
                <asp:ListItem Text="Z" Value="Z"  />
                <asp:ListItem Text="0" Value="0"  />
                <asp:ListItem Text="1" Value="1"  />
                <asp:ListItem Text="2" Value="2"  />
                <asp:ListItem Text="3" Value="3"  />
                <asp:ListItem Text="4" Value="4"  />
                <asp:ListItem Text="5" Value="5"  />
                <asp:ListItem Text="6" Value="6"  />
                <asp:ListItem Text="7" Value="7"  />
                <asp:ListItem Text="8" Value="8"  />
                <asp:ListItem Text="9" Value="9"  />
            </asp:DropDownList>
            </ItemTemplate>
            <EmptyItemTemplate>           

            </EmptyItemTemplate>
        </asp:ListView>


        </td>
    </tr>
    <tr>
        <td>
        <asp:Panel runat="server" ID="pnlEnter" DefaultButton="btnQuery" >
        <asp:Button ID="btnQuery" runat="server" Text="Submit" />
        </asp:Panel>
        </td>
        <td align="right">
        <asp:Button ID="btnAddRow" runat="server" Text="Add Row" />
        </td>
    </tr>
</table>
4

3 に答える 3

2

DefaultButtonパネルの代わりにフォーム タグでプロパティを設定し、asp:button でのプロパティも設定しますUseSubmitBehavior="true"

うまくいけば、それはあなたの問題を解決します.

于 2012-08-27T17:26:04.187 に答える
0

リストビューの上にパネルを作成する必要があります。

<asp:Panel runat="server" ID="pnlEnter" DefaultButton="btnQuery">   // panel should be at top of listview
       <asp:ListView ID="lvQuery" runat="server" >
          .......
          ........
       </aspListView>
       <asp:Button ID="btnQuery" runat="server" Text="Submit" />         
</asp:Panel> 
于 2012-08-27T17:31:47.287 に答える
0

もう 1 つの方法は、「Enter」ボタンを検出してフォームを送信する JavaScript スニペットを作成することです。

    function yourKeyPressFunction(e) {
        if (e.keyCode == 13) {
            this.form.submit();
        }
    }

    <form method="post" onkeypress="yourKeyPressFunction(event)">
于 2012-08-27T17:34:04.743 に答える