Return to the menu   Select another DES Module

Demonstrates the RequiredListValidator

The RequiredListValidator tests if a list-style control has no selection. By default, “no selection” means no item is highlighted or marked. You can change “no selection” to be a particular item, such as the first item in the list.

It is generally used with single selection ListBoxes, DropDownList and RadioButtonLists. For multiple selection ListBoxes and CheckBoxLists, the CountSelectionsValidator is probably a better choice.

Specify the control to evaluate with the ControlIDToEvaluate property.

Use the UnassignedIndex property to change the “no selection” item. Use 0 when the first item indicates "no selection". Use -1 if no selection is when no item is actually selected.


Controls

ListBox

This example applies equally well to a DropDownList and RadioButtonList too.
Unless your setup for "no selection" actually has no selected item, set the UnassignedIndex property to 0 or the index of the ListItem that indicates "no selection".




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>ListBox</h2> This example applies equally well to a DropDownList and RadioButtonList too.<br/> Unless your setup for "no selection" actually has no selected item, set the <span class="PropertyName">UnassignedIndex</span> property to 0 or the index of the ListItem that indicates "no selection".<br/><br/> <asp:ListBox ID="ListBox1" runat="server" > <asp:ListItem Selected="True">Not assigned</asp:ListItem> <asp:ListItem>2</asp:ListItem> <asp:ListItem>3</asp:ListItem> <asp:ListItem>4</asp:ListItem> </asp:ListBox> <des:RequiredListValidator ID="RequiredListValidator1" runat="server" ControlIDToEvaluate="ListBox1" ErrorMessage="required" UnassignedIndex="0" > </des:RequiredListValidator> <br/><br/> <des:Button ID="Button1" runat="server" Text="Submit" OnClick="Button1_Click"></des:Button>

Return to the menu   Select another DES Module