Im writing a hotel booking system with VS2012 which uses ms sql and in the booking i have two datetimepicker controls. When i select a date in the first one the date automatically gets transfered to the second datetimepicker. I now want when the user opens up the second datetimepicker not being able to select a date that is before the first date from the first datetimepicker. I dont want to use if method displaying a message i just want the dates to be "greyed" out.
Is that possible and how?
*edit (screenshot of how i would like it to be viewed or similar http://i43.tinypic.com/2zpimvs.jpg )
*edit2: its not the control(dateTimePicker2) it self i want to grey out, its the dates inside it that is smaller then the date selected in dateTimePicker1. The screenshot provided is in the area of what im looking for.
You could try this:
DateTimePicker2.MinValue = Convert.toDateTime(DateTimePicker1.SelectedDate);
EDIT
Standard controls don't support the grey-out of a datetimepicker. If you want to do this, you need to subclass the datetimepicker or look at a premade control like a DateEdit from devexpress (i think they even have free controls).
Change the second datepicker MinDate to first DatePicker selected date .. like below ..
rdpDatePicker2.MinDate = rdpDatePicker1.SelectedDate.Value;
Related
I have CalendarView on two pages.
First page is used to add records to calendar by assigning the selected date to the database record.
Second page is used to show all records assigned to the selected date.
Now, when on the first page I assign date to the product by clicking the date manually, on the second page product is shown correctly when selected date that corresponds to the products date.
However, when on the first page I add dates to the products programmatically, on the second page, these products are shown one day before than they should.
I have no idea what is happening. I will post code if you want to check something.
THe problem is strange, becaue on one calendar these automatically added dates are shown for example on 5th April, but on the second calendar they are listed under 4th April.
Is that the globalization of two calendars problem?
Locale(globalization ) would be a potential problem. But having code would help us to provide you more info.
I have managed to resolve the problem. It was in deed issue with DateTimeOffset/DateTime values.
I changed every instance of Date I found in the code by appending it with
.LocalDateTime
.
This way I got the correct local date of each DateTimeOffset object and data is added to/ pulled from the Calendar correctly.
I am using the AjaxToolKit Calendar Extender in my application so the user can select their date of birth. Most users that will be using the system will be over the age of 60 so i want this to appear as the default view when the textbox contains no text, i have set the calendar to open up in year mode, but i am unable to get to default to a date 60 years in the past without having anything in the associated textbox.
what i am trying to achieve is what is the picture but when the user open the calendar extender when the textbox contains no values.
#ccStars Try a combination of DefaultView, SelectedDate and PopupButtonID.
DefaultView: will take you to the year mode which you have already done.
SelectedDate: will set a date the calendar is initialized with,
PopupButtonID: the id of a control to show the calendar popup when clicked. If this value is not set, the calendar will pop up when the textbox receives focus. So have a small calendar icon next to your textbox and give its id. This will solve your problem of getting a date only when it is selected in the calendar.
Above are server-side properties. The client-side properties of your interest are:
selectedDate and visibleDate: the difference is that the selectedDate is the value represented by the textbox, but visibleDate is the date currently visible in calendar.
More information here: http://www.asp.net/ajaxlibrary/act_calendar_reference.ashx
You can try to use the Calendar's SelectedDate attribute, like this:
protected void Page_Load(object sender, EventArgs e)
{
calendarExtender.SelectedDate = DateTime.Today.AddYears(-60);
...
}
I know there's not a clear way of doing this, but what if we tried some jury-rigging and testing?
If you set the SelectedDate using Cobra's answer above, I'm assuming it will default to the right date range.
Now, if afterwards, on the client-side, you did some JavaScript to clear out the TextBox, I wonder if the CalendarExtender would still keep the old date ranges?
Using jQuery, here's a quick script to do it. Assumption is that the TextBox's ID is txtDateOfBirth and the ClientIDMode is set to Static.
$('#txtDateOfBirth').val('');
A feature of a forms based application I am developing allows the user to search through a history of records.
The user can search by name, by number, and between dates, and populate the results in a datagridview control.
However, as the form will be used to search for previous records. The ability for the user to select future dates is not required.
Is there a way to prevent the user from selecting future dates, or even grey the future dates out?
You can try with code based on MaxDate property
yourControl.MaxDate = DateTime.Today;
Link : http://msdn.microsoft.com/fr-fr/library/system.windows.forms.datetimepicker.maxdate.aspx
You can use the DateTimePicker.MaxDate Property:
DateTimePicker.MaxDate Property: Gets or sets the maximum date and time that can be selected in the control.
Please try:
dateTimePicker.MaxDate = DateTime.Now;
Setting the MaxDate property will hide all dates after the specified date, and will not allow dates to be entered that are greater than that date.
See http://msdn.microsoft.com/en-us/library/system.windows.forms.datetimepicker.maxdate.aspx for details.
I have an ASP.NET 4 calendar display problem. I want to programmatically set the calendar. So, I put this code in the void Page_Load(object sender, EventArgs e) function:
Calendar1.SelectedDate = DateTime.Parse("2011-07-25");
it works fine. But, it displays the current month of the calendar (August) instead of the date I selected (July). I have to select back one month to see the date that I programmatically assigned.
What should i do?
Thanks!
You need to set the VisibleDate property to the month that you want it to show =)
There is a gotcha that you should be aware of.
If you set the selected date to DateTime.Now or something based on it such as DateTime.Now.AddYears(1) then the selected date will not be highlighted in the calendar even though it is selected.
You need to remove the time component using DateTime.Now.Date so that the calendar can do the comparison correctly when rendering. It took me a bit of debugging in the DayRenderEventHandler to figure that out.
I hope that somebody finds it useful.
is there any way to merge cells in a datagrid view or atleast can we show on the screen like some columns in the grid belongs to one group.
for example ill take three columns:
column1: year field(a drop down type)
column2: month field(a drop down type)
column3: date field(a drop down type)
all these three should be grouped to dateofbirth cell.
or is there any way to embed calendar component in the cell.. just like in some sites when we book some tickets we click on calendar icon & click the date and it will be captured in the corresponding field..
any ideas?
You can create your own DataGridViewCalendarColumn by inheriting from DataGridViewColumn, and a DataGridViewCalendarCell by inheriting from DataGridViewCell or DataGridViewTextBoxCell.
This isn't something I've done myself, but there are loads of tutorials online explaining how to create custom DataGridView columns. A google search may help.
what i have done for this is as follows:
i have taken a date time picker obj,which will be in invisible mode initially.
when i focus on the date of birth cell ,then date time picker will invoke(in a dialog) and will be visible for this focus time.
after selecting the date,the value will be inserted into the current cell.
if the focus is on the next rows and the corresponding cell then once again we follow the above step.