私のコードは
<asp:DropDownList ID="ddlFrom" runat="server" CssClass="From"></asp:DropDownList>
そして私のCSSコードは.From{ width:250px;height:25px}
アイテム数が多いため、高さはあまり大きくできません。ドロップダウンに垂直スクロール バーを追加するにはどうすればよいですか?
Web にはいくつかのサード パーティ コントロールがあり、簡単に bing することができます。DropDownExtender (AJAX ControlToolkit の)、TextBox、ListBox、および数行の Javascript を含む非常に簡単な回避策を用意しました。
ここで、TextBox はリストボックスの選択された値を保持します。以下の私のASPXコード:
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text="Select your item" CssClass="MyTextBox"></asp:TextBox>
<div style="padding: 4px;" id="ItemsDiv" runat="server">
<asp:ListBox ID="ListBox1" runat="server" onclick="callme()" CssClass="MyDropDown" Rows="6">
</asp:ListBox>
</div>
<asp:DropDownExtender ID="DropDownExtender1" runat="server" TargetControlID="TextBox1"
DropDownControlID="ItemsDiv">
</asp:DropDownExtender>
</ContentTemplate>
</asp:UpdatePanel>
<script>
function callme() {
element = document.getElementById("ListBox1");
str = element.options[element.selectedIndex].value;
document.getElementById("TextBox1").value = str;
}
</script>
css クラス addoverflow-y:auto
では、オプションの長さが 25px を超えると、dropdpwn の y 軸にスクロールバーが表示されます。