Solved

how to force user to select values from the dropdownlist

Posted on 2008-10-17
11
350 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
ASP.Net Session State alternatives 3 61
Problem to page 4 74
Connection String 16 43
When should I use a controller? 3 22
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…
This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.

867 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

16 Experts available now in Live!

Get 1:1 Help Now