开发者

How can I create an object in .ascx?

I've wrapped the asp:DropDown cont开发者_开发百科rol 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


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜