2009-05-02 85 views

回答

6

如果所有的单选按钮是相同的RadioButtonList的的一部分,你可以使用一个简单RequiredFieldValidator的。这里有一个例子:

<asp:RadioButtonList 
    ID="RadioButtonList1" 
    runat="server" 
    RepeatColumns="3"> 
    <asp:ListItem>Red</asp:ListItem> 
    <asp:ListItem>Yellow</asp:ListItem> 
    <asp:ListItem>Blue</asp:ListItem> 
    <asp:ListItem>Green</asp:ListItem> 
</asp:RadioButtonList> 
<asp:RequiredFieldValidator 
    ID="ReqiredFieldValidator1" 
    runat="server" 
    ControlToValidate="RadioButtonList1" 
    ErrorMessage="You must Select your favorite color!">* 
</asp:RequiredFieldValidator> 

如果您在不同的RadioButtonLists单选按钮,您要验证至少有一个在多个列表中选择,那么你就需要一个CustomValidator

2

另一种方式可能是,如果您在页面加载过程中默认选中其中的一个(也许是大多数用户将选择的那个),则用户将被“强制”更改选择或继续使用默认选项,通过这种方式你可以确保总有一个选项被选中。

+1

在相同的情况下,您要强制用户做出选择。创建一个默认选择不是一回事。 – Homer 2010-07-21 16:02:52