Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 390
  • Last Modified:

how to force user to select values from the dropdownlist

Experts
I have managed to show date of birth in 3 different dropdownlist for day month and year

It looks something like attached with its default value.

How can I make sure that the user has changed the values in other words force the user to give his birth date by chosing some values.

meaning the date should not be " 1feb 1980"

please can someone advise
thanks
kay
screenshot.jpg
0
learningnet
Asked:
learningnet
  • 4
  • 3
  • 2
  • +1
3 Solutions
 
mirzasCommented:
Put a blank item in each of the dropdowns. It should be first and selected by default.
Later you can validate if the selection is blank which would mean the user did not change anything
or validate if it contains something, then the selection has been made.
0
 
maXXXeECommented:
IMHO, It is better to have the first entry as a blank value. (eg: <asp:ListItem Value="" Text="select"/>)

Because you can easily use validators to check the values are empty or not.
0
 
HeoQueCommented:
1sty you need to put some initial values , like "-day-, -month-, -year-" with values all 0

then use a CutomValidor to validate the 3 dropdownlist to non-0 values !

customvalidtors usage :http://aspnet.4guysfromrolla.com/articles/073102-1.aspx
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
learningnetAuthor Commented:
thanks for your comments folks...

i am trying to use one of the existing class to push data into the date of birth control

without changing FillDropDownList procedure, i tried to add as per your suggestion below ...however, the one i have added is not getting displayed in the drop down ...


<asp:DropDownList ID="lstDayOfYourBirth" runat="server">
                                                                   <asp:ListItem Value="" Text="select" Selected=True/>
                                                                   </asp:DropDownList>

please can you advise

thanks
If Not Page.IsPostBack Then
                    WebFunctions.FillDropDownList(lstYearOfYourBirth, 1890, Year(Now))
                    WebFunctions.FillDropDownListMonths(lstMonthOfYourBirth)
                    WebFunctions.FillDropDownList(lstDayOfYourBirth, 1, 31)
                End If
 
 
 Public Shared Sub FillDropDownList(ByVal lst As DropDownList, ByVal first As Integer, ByVal last As Integer)
        Dim i As Integer
 
        lst.Items.Clear()
        For i = first To last
            lst.Items.Add(New ListItem(i, i))
        Next
    End Sub

Open in new window

0
 
HeoQueCommented:
That's another issue, please posted on a new thread
0
 
maXXXeECommented:
add this in code behind

lst.Items.Add(New ListItem("Select","");

after line14
0
 
mirzasCommented:
It should be after line 11
0
 
mirzasCommented:
It is not displayed because you clear the items,
lst.Items.Clear()

Open in new window

0
 
learningnetAuthor Commented:
thanks maXXXeE:

because this function FillDropDownList is been used in different places i really do not wanted to touch this ...

perhaps  i can make one for my use ...

is there no way i can add or over write this on the aspx page?

thanks for your help
0
 
mirzasCommented:
Create a custom version.

And add

lst.Items.Add(New ListItem("Select","");

after line 11
0
 
maXXXeECommented:
well if it is not possible for u to change the filldropdown methods,

call a function

If Not Page.IsPostBack Then

InitializeDropDowns(lstYearOfYourBirth,lstMonthOfYourBirth,lstDayOfYourBirth)  ' this is function , add you

                    WebFunctions.FillDropDownList(lstYearOfYourBirth, 1890, Year(Now))
                    WebFunctions.FillDropDownListMonths(lstMonthOfYourBirth)
                    WebFunctions.FillDropDownList(lstDayOfYourBirth, 1, 31)



                End If


Inside the function u need to add the values to dropdown


Public Shared Sub FillDropDownList(ByVal lst1 As DropDownList,ByVal lst2 As DropDownList,ByVal lst3 As DropDownList)
lst1.Items.Add(New ListItem("Select","");
lst1.SelectedItem.Value="";

lst2.Items.Add(New ListItem("Select","");
lst2.SelectedItem.Value="";

lst3.Items.Add(New ListItem("Select","");
lst3.SelectedItem.Value="";


end sub





Mind the syntax i am not good at vb, i do only c#. But hope u get the point
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 4
  • 3
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now