|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
validator for drop down list boxJust wondering if anyone knows how to set up a validator for a dropdown list
box, which one to use and what is the validator formula if any. I do not what to allow a post back if the selected index = 0, ok to if anything else. Thanks. -- Paul G Software engineer. Hi,
You can do that with RequiredFieldValidator. Just give it a value as string into InitialValue attribute/property which indicates the cvalue in DropDownList when no selection is made. For example <asp:DropDownList ID="ddl" runat="server"> <asp:ListItem Value="0">Zero</asp:ListItem> <asp:ListItem Value="1">One</asp:ListItem> <%-- More items here ... --%> </asp:DropDownList> <asp:requiredFieldValidator ID="rfv1" ControlToValidate="ddl" runat="server" InitialValue="0" ErrorMessage="Please make a selection" /> Now it understands that item with value "0" is the default one and indicates when nothing is selected. ok thanks for the information. I was not sure how to give it a value that it
would consider not valid and did not see in the properties box of the validator a way to do this. -- Show quoteHide quotePaul G Software engineer. "Teemu Keiski" wrote: > Hi, > > You can do that with RequiredFieldValidator. Just give it a value as string > into InitialValue attribute/property which indicates the cvalue in > DropDownList when no selection is made. > > For example > > <asp:DropDownList ID="ddl" runat="server"> > <asp:ListItem Value="0">Zero</asp:ListItem> > <asp:ListItem Value="1">One</asp:ListItem> > <%-- More items here ... --%> > </asp:DropDownList> > > <asp:requiredFieldValidator ID="rfv1" ControlToValidate="ddl" runat="server" > InitialValue="0" ErrorMessage="Please make a selection" /> > > Now it understands that item with value "0" is the default one and indicates > when nothing is selected. > > -- > Teemu Keiski > ASP.NET MVP, AspInsider > Finland, EU > http://blogs.aspadvice.com/joteke > > >
Custom control: How to render an embedded image at design-time?
Can aspnet simulate windows pane separator? Please Help: ListBox.SelectedItem returns null Web User Controls: Exposing Items property of contained controls Load User Control from different directory ListItem individual Color Collection with the correct object type on the Collection dialog DropDownList <optgroup> Dropdownlist headings Setting control value in Javascript |
|||||||||||||||||||||||