Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Extract Day, Month, Year from Databound Date into DropDownLists

Posted on 2006-07-14
4
Medium Priority
?
447 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 2000 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses

610 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