My goal is to create a composite control that looks like, acts like and behaves like a RadioButtonList. There is some extra things done behind the scenes which are working no problem. What I am unable to accomplish is the desired markup to use the control. My ideal markup looks like this:
<cc1:RadioButtonField ID='rfCardType' runat='server' Title='Card Type:'> <asp:ListItem Enabled='true' Text='MasterCard' /> <asp:ListItem Enabled='true' Text='Visa' /> <asp:ListItem Enabled='true' Text='Amex' /> </cc1:RadioButtonField>
What I would like to do is pass the <asp:ListItems> to the RadioButtonList in the composite control and have that handle everything required to produce/run the control.
Control Markup for RadioButtonField:
<div class='Title'> <asp:Label ID='lblTitle' runat='server' AssociatedControlID='rblField' /> </div> <div class='Text'> <asp:RadioButtonList ID='rblField' runat='server' Visible='true'> </asp:RadioButtonList> </div>
Code Behind for RadioButtonField:
???
What does the RadioButtonField code behind need to do in order to collect the <asp:ListItems> and pass them to the RadioButtonList?
If you want the
<ListItem>style markup, here’s what you’ll have to do:itemsprivate field of typeListItemCollectionto your composite controlItemspublic property of typeListItemCollectionto your composite control. The getter should refer to theitemsprivate field.ParseChildrenclass attribute to your composite control so it will read the list.Your composite control now has the ability to read
ListItemnodes from its markup. When the control renders, all<ListItem>nodes will be added to the privateitemscollection.It would be wonderful if you could now just set the
Itemsmember of the RadioButtonList, but unfortunately it is private. You will have toforeachthrough theitemsfield and call theAdd()method on your child RadioButtonList.