自定义下拉列表,其中项目自动填充
我需要一个包含美国各州的下拉列表。 我可能需要在各个页面上使用此下拉列表。 我不需要总是为每个状态创建一个列表项,而是想要一个简单的控件。 我不需要 UserControl - 我想扩展现有的下拉列表控件。 我知道我以前在以前的雇主那里做过这件事,但我一辈子都不记得该怎么做!
我不能为每个州做这样的事情吗? 如果是的话,在哪里?
MyBase.Items.Add(New ListItem("Illinois","IL"))
有什么想法吗?
谢谢
I have the need for a dropdownlist with the U.S. states in it. I could need this dropdownlist on various pages. Instead of always having to create a listitem for each state, I want a simple control. I don't want a UserControl - I want to extend the existing dropdownlist control. I know I have done this before at a previous employer, but for the life of me I can't remember how to do it!
Can't I just do something like this for each state? If so, where?
MyBase.Items.Add(New ListItem("Illinois","IL"))
Any ideas out there?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您所要做的就是创建一个新类并从适当的控件继承:
在构造函数中只需添加适当的列表框项即可。
您可能需要将其放在不同的项目中并引用 dll。 我想我记得一些关于那件事的事情,但自从我不得不这样做以来已经有一段时间了。
All you have to do is create a new class and inherit from the appropriate control:
In the constructor just add the appropriate listbox items like you have.
You may need to put it in a different project and reference the dll. I think I remember something about that, but it's been a while since I have had to do it.
扩展 DropDownList 控件并覆盖 OnLoad 事件并添加您的项目,如下所示:
Extend DropDownList control and override OnLoad event and add your items like that :