To validate the value selected in the dropdownlist

Asked

Viewed 298 times

0

I am using the Comparevalidator to check if the value selected in the dropdownlist is "Select", but this does not work, follow the code.

<asp:DropDownList ID="ddlIdPisSt" runat="server" DataSourceID="sdsIdPisSt" DataTextField="Descricao"  
    DataValueField="Id" AppendDataBoundItems="True" Width="790px">
    <asp:ListItem Value="">Selecione</asp:ListItem>
</asp:DropDownList>                 
<asp:CompareValidator ID="CompareValidator1" runat="server" ControlToValidate="ddlIdPisSt" Display="Dynamic" 
    ErrorMessage=" * " Operator="NotEqual" ValueToCompare="" ForeColor = "Red">
</asp:CompareValidator>

What I’m doing wrong. Can someone help me.

1 answer

4


Friend, try to use the Requiredvalidator, because the "Select" does not contain value and the Requiredvalidator will take.

Try and tell us if it worked.

  • 1

    Thanks to the tip, Rboschini, to use the Requiredvalidator, just add the property Initialvalue=" " that solved my problem. Thanks.

  • 1

    Give me a wire and I’ll score! ;) Please!!! : D

  • 1

    +1 I gave a joinha only on account of his begging. hahahaa Excellent btw response

  • virtual begging, just do not pass the agency and account for shame even. :p

Browser other questions tagged

You are not signed in. Login or sign up in order to post.