Hi Dominic,
Hummm... after an item has been inserted I don't think there is an easy way
to differentiate if it was defined at design-time or it has added at
runtime. But if you're subclassing DropDownList you can try something like
this:
a) keep a private collection of items that you will fill at OnInit based on
the items that were declared at design-time.
b) add a public method "ResetToOriginalItems", I'm sure you can think of a
better name here ;-) -- in this method you should clear the original item
list and fill it with the list you created at OnInit time thus reverting the
list to the original items specified at design-time.
In code this should look something like this:
[C#]
protected override void OnInit(EventArgs e) {
foreach (ListItem ite in base.Items)
_items.Add (ite);
base.OnInit (e);
}
public void ResetToOriginalItems () {
this.Items.Clear ();
foreach (ListItem ite in _items)
this.Items.Add (ite);
}
This may work for you if you can live with the few assumptions made (no
items will be inserted before OnInit) but it should serve as a good
jumpstart...
--
Victor Garcia Aprea
Microsoft MVP | ASP.NET
Looking for insights on ASP.NET? Read my blog:
http://obies.com/vga/blog.aspx To contact me remove 'NOSPAM'. Please post all questions to the newsgroup
[quoted text, click to view] "Dominic" <anonymous@devdex.com> wrote in message
news:eIHJt1sEEHA.3784@TK2MSFTNGP10.phx.gbl...
> I've created a control inheriting from dropdownlist. What I need is a
> RemoveDynamicItems method that would remove only list items that were
> added programatically. Keeping all list items existing explicitly in
> the designer (aspx file). Any ideas?
>
>
> *** Sent via Developersdex
http://www.developersdex.com ***
> Don't just participate in USENET...get rewarded for it!