Solved

how to force user to select values from the dropdownlist

Posted on 2008-10-17
11
338 Views
Last Modified: 2012-05-05
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
Comment
Question by:learningnet
  • 4
  • 3
  • 2
  • +1
11 Comments
 
LVL 6

Expert Comment

by:mirzas
ID: 22739287
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
 
LVL 7

Expert Comment

by:maXXXeE
ID: 22739310
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
 
LVL 9

Assisted Solution

by:HeoQue
HeoQue earned 150 total points
ID: 22739410
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
 

Author Comment

by:learningnet
ID: 22739435
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
 
LVL 9

Expert Comment

by:HeoQue
ID: 22739460
That's another issue, please posted on a new thread
0
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
LVL 7

Accepted Solution

by:
maXXXeE earned 200 total points
ID: 22739482
add this in code behind

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

after line14
0
 
LVL 6

Expert Comment

by:mirzas
ID: 22739496
It should be after line 11
0
 
LVL 6

Expert Comment

by:mirzas
ID: 22739499
It is not displayed because you clear the items,
lst.Items.Clear()

Open in new window

0
 

Author Comment

by:learningnet
ID: 22739512
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
 
LVL 6

Assisted Solution

by:mirzas
mirzas earned 150 total points
ID: 22739528
Create a custom version.

And add

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

after line 11
0
 
LVL 7

Expert Comment

by:maXXXeE
ID: 22739595
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

759 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now