Solved

Drop Down List for Time and Date selection

Posted on 2004-10-13
8
710 Views
Last Modified: 2010-04-15
Hello, I need to create a drop down list to let a user select the start time and date of an event.  I would like the current date displayed and then the time.  For example the drop down list will have selections ranging grom 7am to 11pm, with the current date in front of the time.

Can anyone help me achieve this?  I'm not sure how to code it.

Thanks
0
Comment
Question by:dabrat
  • 4
  • 3
8 Comments
 
LVL 3

Expert Comment

by:Realmrat
ID: 12305683
Is this a windows application or a ASP.NET application?

 - Joe
0
 
LVL 1

Author Comment

by:dabrat
ID: 12307215
asp.net application
0
 
LVL 3

Expert Comment

by:aacool
ID: 12310902
The code below uses System.Web.UI.WebControls.Calendar and a basic DropDownList - the dropdownlist can be made smarter as needed. Please tell me if this helps.

Try this:

<%@ Page Language="C#" AutoEventWireup="True" %>

<html>
   <script runat="server" >
 
      void Selection_Change(Object sender, EventArgs e)
      {

      // Get the selectedDate
      String selectedDate = Calendar1.SelectedDate.ToShortDateString();
      // Get the selected time
      string selectedTime = TimeList.SelectedItem.Value;
      //do processing with time and date
      // ...      
      }
   </script>
 
<body>
   <form runat="server">
      <h3> Date Time Picker </h3>
      Choose the date and time
      <br>
      <asp:Calendar id="Calendar1"
           ShowGridLines="True"
           ShowTitle="True"
           runat="server"/>
      <br>
      <table cellpadding="5">
         <tr>
            <td>
               Time:
            </td>
         </tr>
         <tr>
            <td>

               <asp:DropDownList id="TimeList"
                    AutoPostBack="True"
                    OnSelectedIndexChanged="Selection_Change"
                    runat="server">
                  <asp:ListItem Selected="True" Value="7:00 AM"> 7:00 AM </asp:ListItem>
                  <asp:ListItem Value="8:00 AM"> 8:00 AM </asp:ListItem>
                  <asp:ListItem Value="9:00 AM"> 9:00 AM </asp:ListItem>
                  <asp:ListItem Value="10:00 AM"> 10:00 AM </asp:ListItem>
                  <asp:ListItem Value="11:00 AM"> 11:00 AM </asp:ListItem>
                  <asp:ListItem Value="12:00 AM"> 12:00 AM </asp:ListItem>
                  <asp:ListItem Value="1:00 PM"> 1:00 PM </asp:ListItem>
               </asp:DropDownList>

            </td>
        </tr>
     </form>
</body>
</html>
0
Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

 
LVL 1

Author Comment

by:dabrat
ID: 12314240
this does not add the currnt date to the drop down list.  I need the drop down list to display current date then the time.

example ( each line would be a selection in the drop down list)

10/14/2004 7:00am
10/14/2004 7:30am

and so on
0
 
LVL 3

Expert Comment

by:aacool
ID: 12321652
Add this function to the Load event of the dropdown list:

private void TimeList_Load(object sender, System.EventArgs e)
{
     //TimeList is the drop down list
      TimeList.Items.Clear;
      //populate array of times - put in all relevant values
      string[] timeArrList = {" 7:00 AM"," 7:30 AM "," 8:00 AM "};
      string currDate = Calendar1.SelectedDate.ToShortDateString();
      for(int i=0;i<timeArrList.Length;i++)
      {
      timeArrList[i] = currDate + timeArrList[i];
      TimeList.Items.Add(timeArrList[i]
      }
}

This will show items in the drop down the way you want. Change the format of the date if you need to show it differently.
0
 
LVL 3

Accepted Solution

by:
aacool earned 50 total points
ID: 12321692
Small coding error  - missing bracket and ;

private void TimeList_Load(object sender, System.EventArgs e)
{
   TimeList.Items.Clear;
   string[] timeArrList = {" 7:00 AM"," 7:30 AM "," 8:00 AM "};
   string currDate = Calendar1.SelectedDate.ToShortDateString();
   for(int i=0;i<timeArrList.Length;i++)
  {
      timeArrList[i] = currDate + timeArrList[i];
      TimeList.Items.Add(timeArrList[i]);
   }
}
0
 
LVL 1

Author Comment

by:dabrat
ID: 12323362
okay the code you gave me works if I do not use my stored procedure but if I use it i get the following error:

The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value. The statement has been terminated
0
 
LVL 1

Author Comment

by:dabrat
ID: 12323997
thank you so much!!!
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
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.

810 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