Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET date and time picker?

Tags:

c#

asp.net

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 advance!!

like image 524
Etienne Avatar asked Nov 13 '09 13:11

Etienne


3 Answers

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
like image 91
David Avatar answered Nov 05 '22 11:11

David


Check out this cool Jquery Date Time Picker.

like image 20
Pragnesh Patel Avatar answered Nov 05 '22 09:11

Pragnesh Patel


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/

like image 1
Jakkwylde Avatar answered Nov 05 '22 10:11

Jakkwylde