<asp:DropDownList ID="DropDownList1" runat="server" style="width:100px;" > </asp:DropDownList>
<asp:CompareValidator ID="CompareValidator1" runat="server" ErrorMessage="请选择类别"
ControlToValidate="DropDownList1" Type="Integer" ValueToCompare="0" ForeColor="Red" Operator="GreaterThan">
</asp:CompareValidator>
验证下拉框是否选中 CompareValidator 控件
errormessage 错误提示信息
controltovalidate 需验证的控件ID
type 字符类型
valuetocompare 用于匹配的数值,如果相等提示错误
operator="greaterthan" 暂时不知道什么意思,但是必须得写上
<asp:TextBox ID="txttitle" runat="server" Width="200" MaxLength="15"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="标题不能为空"
ControlToValidate="txttitle" ForeColor="Red"></asp:RequiredFieldValidator>
验证文本框不为空 RequiredFieldValidator 控件
errormessage 错误提示信息
controltovalidate 验证的控件ID
如果验证不通过不执行button的单击事件 在button的单击事件内加上 if (Page.IsValid)判断