Solved

Extract Day, Month, Year from Databound Date into DropDownLists

Posted on 2006-07-14
4
437 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

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

A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

920 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