Return to the menu   Select another DES Module

Demonstrates the SelectedIndexValidator

The SelectedIndexValidator evaluates the SelectedIndex property of a ListBox, DropDownList, RadioButtonList, or CheckBoxList. You provide an index into the list (starting at 0 for the first item) and whether you want the item at that index to be highlighted/marked or not. The Condition indicates success when the item at the given index matches the desired highlight or mark state.

Also consider these validators:

Specify the control to evaluate with the ControlIDToEvaluate property. The Index property determines the position whose selected state is evaluated, and the Selected property determines the state. Index values start at 0 for the first ListItem.


Controls

ListBox

Must not select '4'.



Multiple selection ListBox

Must include '3' amongst your selections.



RadioButtonList

Don't select '3'



CheckBoxList

Don't select '3'




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> Must not select '4'.<br/><br/> <asp:ListBox ID="ListBox1" runat="server"> <asp:ListItem Selected="True">1</asp:ListItem> <asp:ListItem>2</asp:ListItem> <asp:ListItem>3</asp:ListItem> <asp:ListItem>4</asp:ListItem> </asp:ListBox> <des:SelectedIndexValidator ID="SelectedIndexValidator1" runat="server" ControlIDToEvaluate="ListBox1" ErrorMessage="Don't select '4'" Index="3" Selected="false"> </des:SelectedIndexValidator> <br/> <br/> <h2>Multiple selection ListBox</h2> Must include '3' amongst your selections.<br/><br/> <asp:ListBox ID="ListBox2" runat="server" SelectionMode="Multiple"> <asp:ListItem Selected="True">1</asp:ListItem> <asp:ListItem>2</asp:ListItem> <asp:ListItem>3</asp:ListItem> <asp:ListItem>4</asp:ListItem> </asp:ListBox> <des:SelectedIndexValidator ID="SelectedIndexValidator2" runat="server" ControlIDToEvaluate="ListBox2" ErrorMessage="Must select '3' amongst your other selections" Index="2" Selected="true"> </des:SelectedIndexValidator> <br/> <br/> <h2>RadioButtonList</h2> Don't select '3'<br/><br/> <asp:RadioButtonList ID="RadioButtonList1" runat="server"> <asp:ListItem Selected="True">1</asp:ListItem> <asp:ListItem>2</asp:ListItem> <asp:ListItem>3</asp:ListItem> <asp:ListItem>4</asp:ListItem> </asp:RadioButtonList> <des:SelectedIndexValidator ID="SelectedIndexValidator3" runat="server" ControlIDToEvaluate="RadioButtonList1" ErrorMessage="Don't select '3'" Index="2" Selected="false"> </des:SelectedIndexValidator> <br/> <br/> <h2>CheckBoxList</h2> Don't select '3'<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:SelectedIndexValidator ID="SelectedIndexValidator4" runat="server" ControlIDToEvaluate="CheckBoxList1" ErrorMessage="Don't select '3'" Index="2" Selected="false"> </des:SelectedIndexValidator> <br/><br/> <des:Button ID="Button1" runat="server" Text="Submit" OnClick="Button1_Click"></des:Button>

Return to the menu   Select another DES Module