Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

how to force user to select values from the dropdownlist

Posted on 2008-10-17
11
364 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
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 

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
 
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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

789 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