我的代碼是如何在asp下拉列表中添加垂直滾動條?
<asp:DropDownList ID="ddlFrom" runat="server" CssClass="From"></asp:DropDownList>
和我的CSS代碼是.From{ width:250px;height:25px}
高度不能太大,因爲有大量的它的項目。 如何添加垂直滾動條到我的下拉菜單中?
我的代碼是如何在asp下拉列表中添加垂直滾動條?
<asp:DropDownList ID="ddlFrom" runat="server" CssClass="From"></asp:DropDownList>
和我的CSS代碼是.From{ width:250px;height:25px}
高度不能太大,因爲有大量的它的項目。 如何添加垂直滾動條到我的下拉菜單中?
在網絡上有幾個第三方控件,你可以輕鬆地將它們暴露。我只是提出了一個非常簡單的解決方法,包括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類添加overflow-y:auto
,當博揚25px的選項長度的增加,你會得到你的dropdpwn的y軸滾動條
我嘗試過overflow:auto,但它對下拉菜單沒有任何影響 – mck 2013-05-13 07:31:36
選項1.刪除下拉的高度,使得它會自動增長
選項2.如果是在一個表格單元格或一些東西,不允許它生長然後把它放在一個div像下面
<div style="overflow-y:scroll; height:50px;
overflow: -moz-scrollbars-horizontal;">
<select....></select>
</div>
這裏有一些例子click here
什麼是「溢出-Y:滾動」在你的CSS? – Alex 2013-05-13 07:05:09