Link to home
Start Free TrialLog in
Avatar of VBdotnet2005
VBdotnet2005Flag for United States of America

asked on

dropdowlist

Is it possible to use Fieldvalidator on a dropdowlist in asp.net?
sample :
please select...
book
computer
etc
Avatar of VBdotnet2005
VBdotnet2005
Flag of United States of America image

ASKER

I meant a Requiredfieldvalidator
RequiredFieldValidator?

Yes you can use it with a dropdown. You need to set InitialValue property to value of "please select...".
ASKER CERTIFIED SOLUTION
Avatar of Juan_Barrera
Juan_Barrera
Flag of New Zealand image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Is not based on index, but on the value. If the value for "please select...' is 0, then is ok, but that is not necessary so...
In the example the asker gave, there was no indication of value, so the name would be used.

Anyway, bottom line is: Use the value of the "please select..." item to set the "InitialValue" property.
Yeah..got the point. I had the general convention we use in mind (integers for values) and I assumed that you are using Text instead of value for the InitialValue property.

My Bad. :)
All good, believe me that I didn't mean to sound pedantic or anything like that....just wanted to clarify :)
I fill my dropdownlist from a table. I followed as suggest above. It did not validate it.

... part of it

using AD as new sqldataadapter(sqlComnd)
dim ds as new dataset
dropdownlist.items.insert(0, "Please Select...")
AD.fill(ds, "table1")

etc ...



Using AD As New SqlDataAdapter(sqlComnd)
            Dim dropdownlist As New DropDownList
            Dim ds As New DataSet
           dropdownlist1.Items.Insert(0, New ListItem("Please Select...","0")
            AD.Fill(ds, "table1")

   <asp:DropDownList ID="DropDownList1" runat="server" CausesValidation="true" AppendDataBoundItems="true" >
        </asp:DropDownList>
        <asp:RequiredFieldValidator ControlToValidate="DropDownList1" InitialValue="0"
            ID="RequiredFieldValidator1" runat="server" ErrorMessage="RequiredFieldValidator"></asp:RequiredFieldValidator>
SOLUTION
Avatar of Obadiah Christopher
Obadiah Christopher
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Sorry, I got it.

instead of Please select... I put this Please Select...  it is case sensitive

thank you guys