Custom CheckBoxList in ASP.NET
Since the ASP.NET CheckBoxList control does not allow it to be validated using one of the standard checkboxes (i.e. RequiredFieldValidator), I would like to create a UserControl that I can use in my project when I need a checkbox list that requires one or several boxes.
The standard CheckBoxList can be dragged onto the page, and then you can manually add controls <asp:ListItem>
if you like. Is there a way to create a UserControl that allows me to manually (in markup, not programmatically) insert ListItems from my page in a similar way?
In other words, can I insert a UserControl into the page, and then from the Designer view on the page (i.e. not the Designer view of the UserControl), can I manually add my ListItems like this:
<uc1:RequiredCheckBoxList>
<asp:ListItem Text="A" value="B"></asp:ListItem>
<asp:ListItem Text="X" value="Y"></asp:ListItem>
</uc1:RequiredCheckBoxList>
If the UserControl doesn't work for the end result I'm looking for, I'm open to other suggestions.
Note that I am aware of the CustomValidator control (which I plan to check in my UserControl). It just hurts me to write the same basic code every time I need one of these required checkboxes, so I want to create a reusable control.
source to share
An easier way to solve this problem is to use the standard CheckBoxList, but create a dedicated server checker specifically for the CheckBoxList. The following article shows you how to do this - Create Validator Controls for CheckBox and CheckBoxList .
source to share