gpt4 book ai didi

c# - Asp.Net 下拉列表设置项目 View 限制

转载 作者:行者123 更新时间:2023-11-30 21:47:49 25 4
gpt4 key购买 nike

我在 Asp.Net 页面中有一个国家 DropDownList。我从数据库绑定(bind) DropDownList。它给了我 239 项。页面滚动非常大。

所以,我的问题是如何在下拉列表中设置 10 个项目,然后在列表中滚动。

<asp:DropDownList ID="ddlcountry" AutoPostBack="true" AppendDataBoundItems="true"
runat="server" OnSelectedIndexChanged="ddlcountry_SelectedIndexChanged">
</asp:DropDownList>

最佳答案

实际上这是一个非常有趣和棘手的任务,我们需要为此做一些配置和应用一些 css

DropDownList 没有内置滚动条,因此我们需要使用 OnMouseDown、OnFocusOut、OnDblClick 属性手动执行此操作

<asp:DropDownList ID="ddlcountry" AutoPostBack="true" AppendDataBoundItems="true"
runat="server"
CssClass="DDlCountry"
OnMouseDown="this.size=5;"
OnFocusOut="this.size=1;"
OnDblClick="this.size=1;">
</asp:DropDownList>

为此 DDlCountry 添加新的 CSS 类

.DDlCountry {
width: 128px;
margin: 0 15px 0 0;
font: 12px tahoma;
max-height: 200px;
overflow-y: scroll;
position: relative;
}

关于c# - Asp.Net 下拉列表设置项目 View 限制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38116340/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com