添加使用 DropDownLIst 向复合控件提供列表项的功能
我正在为 DropDownList 创建一个复合控件(还包括一个标签)。
我的想法是,我可以像使用下拉列表一样使用我的控件,但也可以让它在 DDL 前面的页面上放置一个标签。
我的这个功能非常适合文本框,但由于要填充 DDL 的集合(或数据源)组件,我正在努力处理 DDL。
基本上我希望能够做这样的事情:
<ecc:MyDropDownList ID="AnimalType" runat="server" LabelText="this is what will be in the label">
<asp:ListItem Text="dog" Value="dog" />
<asp:ListItem Text="cat" Value="cat" />
</ecc:MyDropDownList>
问题是,我没有为我的控件扩展 DropDownList 类,所以我不能简单地用这个魔法来工作。我需要一些指示来弄清楚如何将我的控件 (MyDropDownList)(当前只是一个 System.Web.UI.UserControl)转换为接受标记内的列表项的控件,理想情况下,我希望能够将其插入数据源(与常规 DDL 提供的功能相同)。
我尝试扩展常规 DDL,但没有成功,但无法让 Label
组件随之运行。
I'm creating a composite control for a DropDownList (that also includes a Label).
The idea being that I can use my control like a dropdown list, but also have it toss a Label onto the page in front of the DDL.
I have this working perfectly for TextBoxes, but am struggling with the DDL because of the Collection (or Datasource) component to populate the DDL.
Basically I want to be able to do something like this:
<ecc:MyDropDownList ID="AnimalType" runat="server" LabelText="this is what will be in the label">
<asp:ListItem Text="dog" Value="dog" />
<asp:ListItem Text="cat" Value="cat" />
</ecc:MyDropDownList>
The problem is, I'm not extending the DropDownList class for my control, so I can't simply work it with that magic. I need some pointers to figure out how I can turn my control (MyDropDownList), which is currently just a System.Web.UI.UserControl
, into something that will accept List items within the tag and ideally, I'd like to be able to plug it into a datasource (the same functions that the regular DDL offers).
I tried with no luck just extending the regular DDL, but couldn't get the Label
component to fly with it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
经过一些挖掘和搜索后,我找到了一个可行的解决方案。希望这能帮助其他人在未来:
After doing some digging and searching I found a solution that works. Hopefully this will help someone else out in the future:
最简单的方法是返回扩展 DropDownList 控件的原始选项。您在使用标签时遇到了哪些问题?这些问题可能更容易解决?
The easiest thing would be to go back to your original option of extending the DropDownList control. What problems did you have getting the label to work with it? Those problems are probably easier to solve?