Solved

Extract Day, Month, Year from Databound Date into DropDownLists

Posted on 2006-07-14
4
444 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
[X]
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
  • 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
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…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

696 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