I am trying to write a template custom control in C#, ASP.NET that will have a collection of items. I’d like to use it similarly to the built-in DropDownList control in ASP.NET, but my items will have different properties.
I noticed that the ListItem class that is used to represent the items in a DropDownList control (or any list control) implements the IParserAccessor interface. When should I implement this interface and what should I do in its AddParsedSubObject(object obj). I’ve searched the internet but I could not find an example or a good explanation for it.
I assume that my custom control’s items will make it without implementing that interface, but still, just out of curiosity, I’d be glad to know more about it.
You don’t need to implement IParserAccessor to get functionality like what you are talking about. Instead create a collection to hold the child controls (we’ll call it Items) in your server control and apply the
ParseChildrenattribute to your server control with “Items” as the DefaultProperty value.The following link contains an example on how to implement ParseChildren:
http://msdn.microsoft.com/en-us/library/aa310907(v=vs.71).aspx
Update
Information on IParserAccessor :
From: http://msdn.microsoft.com/en-us/library/system.web.ui.iparseraccessor.aspx
From: http://forums.asp.net/t/879797.aspx/1 (see imagemaker’s post):
Here is an examle from the same post: