Reputation: 7201
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!!
Upvotes: 5
Views: 27692
Reputation:
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
Upvotes: 0
Reputation: 1302
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/
Upvotes: 1
Reputation: 73564
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
Upvotes: 5
Reputation: 113
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.
Upvotes: 0