views:

154

answers:

5

I am using ASP.NET 2.0 with SQL Server 2005. I want my user to select a date and time and then save those values into the database. In VS I can use the Calendar control to get the date, but what is a good one for handeling the date the user select plus the time what ever it might be that the user must also select from a control.

Thanks in advanced!!

+2  A: 

Here's a nice free control: http://www.asp.net/community/control-gallery/item.aspx?i=535

And another (so you have a choice)

http://www.asp.net/community/control-gallery/item.aspx?i=3221

Although to be perfectly honest, I normally just use drop-down lists and combine them in code-behind. (Although this could be wrapped in a user control fairly easily.)

ASPX:

<asp:TextBox ID="txtTime" runat="server" Width="90px"></asp:TextBox>
<asp:DropDownList ID="ddlAmPm" runat="server">
   <asp:ListItem Selected="True">AM</asp:ListItem>
   <asp:ListItem Selected="False">PM</asp:ListItem>
</asp:DropDownList>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="txtTime" ErrorMessage="*"></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="TimeValidator" runat="server" ControlToValidate="txtTime" Display="Dynamic" ErrorMessage="Invalid Time.  Enter time in a valid format.  Example: 12:30 or 5:00" ValidationExpression="^(1[0-2]|[1-9]):[0-5][0-9]$" EnableClientScript="False"></asp:RegularExpressionValidator>

VB Code-behind:

 Dim strDateTime As String = txtDate.Text & " " & txtTime.Text & " " & ddlAmPm.SelectedItem.Value
David Stratton
A: 

You can use jQuery controls to provide the DateTime picker and just have them dump the selected DateTime into a textbox that the rest of the app can use. Won't work for non-Javascript cases, but otherwise it should be okay.

Jarret R
A: 

I'd go with the JQuery UI datepicker. You can customize the date format and language to fit your need and perform actions like restrict the selectable date ranges and add in buttons and other navigation options. In addition to this there are a variety of keyboard shortcuts that are quite nice when you get used to them.

http://jqueryui.com/demos/datepicker/

Used to use both ASP.net AJAX calendar control but would often have CSS formatting issues and weird cases with client side required field validators not working properly. Since then, the jquery datepicker has proven to be a better fit in instances where I use it.

You can find a good tutorial on how to use the jquery datepicker it here:

http://elegantcode.com/2008/05/06/using-jquery-datepicker-in-aspnet/

Jakkwylde
+2  A: 

Check out this cool Jquery Date Time Picker.

Pragnesh Patel
A: 

I've found the calender extender from the asp.net ajax toolkit to be very easy to use:

http://www.asp.net/AJAX/AjaxControlToolkit/Samples/Calendar/Calendar.aspx

cpeppers