如何在 .ascx 中创建对象?

发布于 2024-10-31 15:51:03 字数 553 浏览 1 评论 0原文

我已经包装了 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

无人问我粥可暖 2024-11-07 15:51:03

并添加您想要的额外属性,这将允许您执行如下操作:

<Control:DropDown id="mycontrol" runat="server" DropDownListLabel="Some Choice:" ..>
    <asp:ListItem Text="<no filter" value="-1" />
    ...
</Control:DropDown>

您可能应该创建从 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:

<Control:DropDown id="mycontrol" runat="server" DropDownListLabel="Some Choice:" ..>
    <asp:ListItem Text="<no filter" value="-1" />
    ...
</Control:DropDown>

Where DropDownListLabel is an added property. Of course in your case you'd add QueryString as a property as well

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文