Solved

Extract Day, Month, Year from Databound Date into DropDownLists

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

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

Suggested Solutions

Title # Comments Views Activity
HTML table 7 54
Async and await with MVC and Web Api 3 30
JavaScript error 1 34
SQL best practice question 3 20
I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

747 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

11 Experts available now in Live!

Get 1:1 Help Now