我的网页上有拖拽列表,如下所示。
<asp:DropDownList ID="JobDDL" runat="server" class="form-control" ValidationGroup="gg" >
</asp:DropDownList>
<asp:RequiredFieldValidator InitialValue="-1" ID="Req_ID" Display="Dynamic"
ValidationGroup="gg" runat="server" ControlToValidate="JobDDL"
Text="*" ErrorMessage="أختر الفرع من فضلك"></asp:RequiredFieldValidator>
<asp:DropDownList ID="BranchDDL" runat="server" class="form-control">
</asp:DropDownList>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="BranchDDL" ErrorMessage="أختر الفرع من فضلك" InitialValue="اختر من فضلك" ForeColor="red"></asp:RequiredFieldValidator>
frist Dropdownlist RequiredFieldValidator(ID =“JobDDL”)不起作用。第二个RequiredFieldValidatorworks(ID =“BranchDDL”)
答案 0 :(得分:0)
请在必填字段验证器
中添加Display =“Dynamic”和Initial value =“Select”如果您的下拉列表第一个元素有选择值,请在必填字段验证器中添加初始值=“选择”。
<asp:RequiredFieldValidator ID="RequiredFieldValidator5" runat="server" ControlToValidate="DropDownList1" ErrorMessage="Please Select Type" InitialValue="--Select--" Font-Bold="True" ForeColor="#CC0000" Display="Dynamic"></asp:RequiredFieldValidator>