Return to the menu   Select another DES Module

Demonstrates the CountSelectionsValidator

The CountSelectionsValidator demands a specific number of selected items in a CheckBoxList or multiselection ListBox.

Specify the ID of the field in the ControlIDToEvaluate property.

Use the Minimum and Maximum properties to specify the range. If you want to consider the range invalid and those values outside the range to be valid, set NotCondition to true.

The ErrorMessage and SummaryErrorMessage properties supports the tokens "{MINIMUM}" and "{MAXIMUM}". They are replaced by the value in the Minimum and Maximum properties respectively.


Controls

Example 1

Using a Multiselection ListBox with Minimum=2. Select a minimum of 2



Example 2

Using a Multiselection ListBox. This example uses the NotCondition to invert the range from Minimum=2 and Maximum=3, so only 1 and 4 selections are permitted.
Select only one or all.




Example 3

Using CheckBoxList with Maximum=2. Select no more than 2 items.



 

Source Code (C#)

<script runat="server">
protected void Button1_Click(object sender, EventArgs e) { if (PeterBlum.DES.Globals.WebFormDirector.IsValid) { // save your data here } }
</script> <h2>Example 1</h2> Using a Multiselection ListBox with <span class="PropertyName">Minimum</span>=2. Select a minimum of 2<br/><br/> <asp:ListBox ID="ListBox1" runat="server" SelectionMode="Multiple"> <asp:ListItem>1</asp:ListItem> <asp:ListItem>2</asp:ListItem> <asp:ListItem>3</asp:ListItem> <asp:ListItem>4</asp:ListItem> </asp:ListBox> <des:CountSelectionsValidator ID="CountSelectionsValidator1" runat="server" ControlIDToEvaluate="ListBox1" ErrorMessage="Select at least {MINIMUM} items" Minimum="2"> </des:CountSelectionsValidator> <br/><br/> <h2>Example 2</h2> Using a Multiselection ListBox. This example uses the <span class="PropertyName">NotCondition</span> to invert the range from <span class="PropertyName">Minimum</span>=2 and <span class="PropertyName">Maximum</span>=3, so only 1 and 4 selections are permitted.<br/> Select only one or all.<br/> <br/><br/> <asp:ListBox ID="ListBox2" runat="server" SelectionMode="Multiple"> <asp:ListItem>Blue</asp:ListItem> <asp:ListItem>Green</asp:ListItem> <asp:ListItem>Red</asp:ListItem> <asp:ListItem>Yellow</asp:ListItem> </asp:ListBox> <des:CountSelectionsValidator ID="CountSelectionsValidator2" runat="server" ControlIDToEvaluate="ListBox2" ErrorMessage="Select one or all" Minimum="2" Maximum="3" NotCondition="true"> </des:CountSelectionsValidator> <br/><br/> <h2>Example 3</h2> Using CheckBoxList with <span class="PropertyName">Maximum</span>=2. Select no more than 2 items.<br/><br/> <asp:CheckBoxList ID="CheckBoxList1" runat="server"> <asp:ListItem>1</asp:ListItem> <asp:ListItem>2</asp:ListItem> <asp:ListItem>3</asp:ListItem> <asp:ListItem>4</asp:ListItem> </asp:CheckBoxList> <des:CountSelectionsValidator ID="CountSelectionsValidator3" runat="server" ControlIDToEvaluate="CheckBoxList1" ErrorMessage="Select no more than {MAXIMUM} items" Maximum="2"> </des:CountSelectionsValidator> <br/><br/> <des:Button ID="Button1" runat="server" Text="Submit" OnClick="Button1_Click"></des:Button> 

Return to the menu   Select another DES Module