0

Good Day Everyone. i have this drop down list

<asp:DropDownList ID="MonthDropDownList" runat="server">
    <asp:ListItem>--select--</asp:ListItem>
    <asp:ListItem Value="1">January</asp:ListItem>
    <asp:ListItem Value="2">February</asp:ListItem>
    <asp:ListItem Value="3">March</asp:ListItem>
    <asp:ListItem Value="4">April</asp:ListItem>
    <asp:ListItem Value="5">May</asp:ListItem>
    <asp:ListItem Value="6">June</asp:ListItem>
    <asp:ListItem Value="7">July</asp:ListItem>
    <asp:ListItem Value="8">August</asp:ListItem>
    <asp:ListItem Value="9">September</asp:ListItem>
    <asp:ListItem Value="10">October</asp:ListItem>
    <asp:ListItem Value="11">November</asp:ListItem>
    <asp:ListItem Value="12">December</asp:ListItem>
</asp:DropDownList>

and i have this range validator

<asp:RangeValidator ID="RangeValidator1" runat="server" ControlToValidate="MonthDropDownList"
                    ErrorMessage="RangeValidator" MaximumValue="1000" MinimumValue="1" ValidationGroup="group1">*</asp:RangeValidator><br />

the question is why does not it act what i want? it supposed to trigger the validator if the --select-- is selected if January up to December is selected it should be allowed

what happens is it only accepts some months. please refer to the screen shots

This is correct because the word --select-- is selected

Right

This is again correct because it is accepted (all of the months should be accepted only the term --select-- when selected should trigger the validator)

Right

But this. when i select the months from february to September the validator triggers WRONG

and that's not what i want. so can you help me why this phenomenon happens?

the range validator should only work if values are inside 1->1000 values of february are inside the range. that's why i really do not know whats happening.

HELP:)

4

1 回答 1

2

give the Type as Integer in your RangeValidator, if you don't specify the type it will compare as strings, since the default Type value is String.

<asp:RangeValidator  Type=Integer  ....

and also give out of range value to default item

<asp:ListItem Value="-1">--select--</asp:ListItem>
于 2013-10-01T06:32:12.137 回答