如何在 .ascx 中创建对象?
我已经包装了 asp:DropDown 控件,以便我可以创建它的许多实例,所有这些实例都使用相同的附加功能。我希望能够在 .ascx 中完全创建这个对象,而不是使用后面的代码。我已经快到了,除了 ListItems 之外。
这是我到目前为止所拥有的,任何人都可以帮助我弄清楚如何填充列表项吗?
<Control:DropDown ID="choice" runat="server" DropDownListLabel="Some Choice:"
QueryString="choice" SelectedIndex="0" ListItems='<%# new ListItemCollection(){
new ListItem("<no filter>", "-1"), new ListItem("Yes", "y"), new ListItem("No", "n")
} %>' />
尽管列表项确实按照后面代码的预期工作,但除 ListItems 外,一切都正常。有关如何正确调用 ListItems 访问器的任何帮助吗?
提前致谢, 布雷特
I've wrapped the asp:DropDown control so that I can create a lot of instances of it, all of which using the same additional functionality. I want to be able to create this object completely in the .ascx rather than using the code behind. I'm almost there, with the exception of the ListItems.
Here's what I have thus far, can anyone help me to figure out how to get the list items to populate?
<Control:DropDown ID="choice" runat="server" DropDownListLabel="Some Choice:"
QueryString="choice" SelectedIndex="0" ListItems='<%# new ListItemCollection(){
new ListItem("<no filter>", "-1"), new ListItem("Yes", "y"), new ListItem("No", "n")
} %>' />
Everything is working, with the exception of the ListItems, although the list items do work as expected from code behind. Any help on how I can get the ListItems accessor to call properly?
Thanks in advance,
Brett
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
并添加您想要的额外属性,这将允许您执行如下操作:
您可能应该创建从 System.Web.UI.WebControls.DropDownList 继承的控件,然后覆盖渲染 一个附加属性。当然,在您的情况下,您也可以添加 QueryString 作为属性
You probably should have created your control to inherit from
System.Web.UI.WebControls.DropDownList
then override rendering and add properties that you want extra, this would allow you to something like the following:Where DropDownListLabel is an added property. Of course in your case you'd add QueryString as a property as well