Solved

Extract Day, Month, Year from Databound Date into DropDownLists

Posted on 2006-07-14
4
440 Views
Last Modified: 2010-10-05
I want to let users update their "Birthdate" using drop-down lists. The "Birthdate" is stored as smalldatetime in SQL Server 2005 Express, and I am using a Formview for updates.

The problem I have is that I don't know how to extract the Month, Day, and Year from the date and use them to get the selected values from three dropdownlists (For Month, Day, Year). For Inserting new records, it's no big deal, since I can make the entire date from the dropdown fields. However, when I display the Update page, I want the user's birthdate to already be selected in the dropdowlists so he/she doesn't have to input it again.

I was thinking I could have the 3 dropdownlists with the "SelectedValue" property bound to the "Birthdate" and then trim off parts of the date. For example using: <%# LEFT(DataBinder.Eval(Container.DataItem, "BirthDate"),2) %> to get the month. But this only works for double digit months.

Any ideas?

Thanks in advance.
0
Comment
Question by:Skytide
  • 2
  • 2
4 Comments
 
LVL 7

Accepted Solution

by:
pradeepsudharsan earned 500 total points
ID: 17113115
<%#Month(DataBinder.Eval(Container.DataItem, "BirthDate"))
& "/" & Day(DataBinder.Eval(Container.DataItem, "BirthDate")) & "/" &
Year(DataBinder.Eval(Container.DataItem, "BirthDate")) %>
0
 
LVL 7

Expert Comment

by:pradeepsudharsan
ID: 17113142

Month:
-------------
'<%#Month(DataBinder.Eval(Container.DataItem, "BirthDate"))%>'

day:
----------
'<%#Day(DataBinder.Eval(Container.DataItem, "BirthDate"))%>'

Year
--------

'<%#Year(DataBinder.Eval(Container.DataItem, "BirthDate"))%>'

Pass these values to one java script function.


function setDate(mon,day,year)
{
document.Form1.cboValues1.value=mon;
document.Form1.cboValues2.value=day;
document.Form1.cboValues3.value=year;

}

regards
pradeep
0
 

Author Comment

by:Skytide
ID: 17113379
Thanks. I got it to work. For some reason I was able to bind the data in the dropdownlist using the "SelectedValue" property for the MONTH and DAY, but I had to use the "SelectedIndex" property for the Year (otherwise I get an error using the "SelectedValue"). I'm not sure why this would happen, since values and index were both populate.

Anyways, Thanks for the help!
0
 

Author Comment

by:Skytide
ID: 17113392
Typed a little too soon. Using "SelectedIndex" doesn't select the correct item.....going to look into this more.
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
What .NET URL re-routing tool did I use? 2 54
Server Error 11 58
designing in object programming 12 75
Question about JQuery and asp.net 3 23
Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
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.
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

813 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

13 Experts available now in Live!

Get 1:1 Help Now