如何仅在列表打开时将下拉菜单中的选项设为第一个选项?
我有一个 DropDownList,其中填充了 SQL 查询返回的值。填充列表后,我手动向此下拉菜单添加两个选项:-- Select --
和 ALL
。
页面加载时,DropDownList 显示 -- Select --
作为默认值。当用户打开 DropDownList 时,SQL 查询返回的列表也会与 ALL
选项一起打开。
我想让这个 ALL
在列表打开时显示为列表中的第一项。我无法使用: DropDownList.SelectedIndex
因为我想已经将 -- Select --
作为所选索引。
如何使 ALL
成为列表打开时的第一个选项?
I have a DropDownList that is filled with values returned by a SQL Query. After the list is filled, I add two options manually to this DropDown: -- Select --
and ALL
.
When the page loads, the DropDownList shows -- Select --
as the default value. When the user opens the DropDownList, the SQL Query returned list opens along with ALL
option also.
I want to make this ALL
appear as the fist item in the list when the list opens. I can't used: DropDownList.SelectedIndex
because I want have already made -- Select --
as the selected index.
How to make ALL
the first option when the list opens?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我想一种解决方案是结合使用文本框/下拉列表。并在文本框中选择默认文本。下拉列表中的第一个选项是“全部”。然后禁用文本框的编辑,使其显示为常规下拉列表。
像这样: 文本框和下拉列表组合
希望这有帮助。
I guess one solution would be to use a textbox / dropdownlist combined. And have the select text as default in the textbox. And the first option in dropdownlist would be ALL. Then disable the editing of the textbox to make it appear as a regular dropdownlist.
Like this: Textbox and dropdownlist combined
Hope this helps.
据我所知,您的梦想是拥有这样的下拉列表
您可以这样做
As much as I understand your dream is to have a dropdownlist like this
You can do this