how to retrieve the date via session variables? - c#

So here is the scenario:
Page1.aspx:
I created a read-only textbox, followed by a simple calendar.
On selecting the date, the long date appears in the textbox.
Page1.aspx.cs:
created a session and stored the date in it.
Page2.aspx:
Created a label field to house the date value.
Page2.aspx.cs:
now i want to rerieve the date value into the label.
Problem1: on selecting the date from the calendar, the page refreshes and then the data is reflected into the textbox
Problem2: can't convert and store the date values into the label.
Please help.

DataType variable=(Datatype)Session["SessionVariable"];
Retrieve like this by typecasting the session value to its appropriate type.
For Example:
Date variable=(Date)Session["date"];

I'm not sure I understand Problem1 correctly, but it seems that you would like the page to display the date in the textbox without reloading. In that case, take a look at jQuery UI's Datepicker: http://jqueryui.com/datepicker/
As to Problem2, you probably can fix that by creating a new DateTime object with the Parse method. The other way around (from DateTime to string) can be done with the ToString method.

Related

How to change Datetime format in a DataGridView cell

I am stucked about datagridview control in which i need to type datetime format in a cell like my own format i need.
I want from the client to enter datetime like "mm/dd" and hit enter, then this field will be seen as a short datetime format.
For example: Client will write "06/27" and hit enter. In cell, it will show 06/27/2015. (The year that we are in). Why i need is that, i will be able to send data in a format that in SQL server accepts.
Should i need also to use it with datetimepicker control or without it i can also handle it?
Well, if you really need to change the value of cell you can use dataGridView_CellEndEdit event and then access cell with:
var cell = dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex];

Change value of DateTimePicker

I'm having problem to change the displayed value of my DateTimePicker object in C# Winforms
I'm trying to change the date in the DateTimePicker according to the value, but the display won't change.
dtpDisplayTo.Value = DateTime.Today;
I know this is dated, but I just had the same problem and found a solution with a bit of research. You have to set the Checked property of the DateTimePicker to True before changing the date, otherwise the control will consider the change as null and not show the new date. Really strange stuff.
DateTimePicker displays today's date instead of displaying its actual Value

Datatable and Date Column Manipulation

I am working on a database driven c# application.
I have a datatable that has a date column in it. Bind this datatable to datagridview and let the user edit the records and upon clicking save, save these changes in the database.
Date format in grid changes based on the system settings between dd/MM/yyyy and MM/dd/yyyy.
Data entry operators are not smart enough to look at this difference, so while editing the records they sometime move the records to different month.
Date Format is dd/MM/yyyy 10/10/2010
They want to change it to 12th October from 10th October. They made this change 10/12/2010 assuming the date format is MM/dd/yyyy.
There always remains this problem, so I want to fix the date format in the datatable.
What are the approaches I could use?
Use this code
var style = new DataGridViewCellStyle();
style.Format = "dd-MMM-yy";
colDate.DefaultCellStyle = style;
You don't need to convert it back and forth, it'll do all the things you want to achieve,
Are you setting the Column DataType as DateTime? I don't understand why this issue can occur. Internally, .NET should be saving this cell value as DateTime, and passing this to the database. Date formatting is not an issue.

Configuring the Date Popup on the WPF DatePicker Control

I have a date picker control that I use for a data collection application. It is using MvvM data binding. When going through a list of dates (see fig1) it will populate the date picker correctly. Whenever I hit new, the date pickers are nulled out. When I pull up the popup, it selects the month and year from the previous date that was set to. (fig 2) Is there anyway to default the pop up show the current month in the current year?
Note : I would like to keep the selected date to null on a new entry to force some validation.
Fig 1
Fig 2
The following image is to show what happens when I set the DisplayDateStart.
(original answer was horribly wrong, sorry about that)
Okay, lets try this again.
Have you tried setting the fallback to today's date?
SelectedDate="{Binding TehDate, FallbackValue={x:Static sys:DateTime.Now}}"

Take the datepicker value

i have a gridview that dynamically generate datepicker , i have taken the value of datepicker using
GMDatePicker dtp = (GMDatePicker)Gridview1.Rows[rowIndex].Cells[3].FindControl("frmdate_starttime");
and i have inserted using dtp.Date,while storing in the database it only store the date and not the time. how to retrive the time to save in database along with date
You can change the Format property to Custom and the CustomFormat property to what you require, something like dd MMM yyyy hh:mm.
You should then be able to use
DateTime dt = dateTimePicker1.Value;
to get the date and time.
Split the problem into two parts: are you getting the right value out of the control but failing to save/restore it in the database correctly, or are you failing to get the right value out of the control in the first place? Once you've worked out whether it's a UI or database problem, you can ignore the other half of it.
Have you enabled the time picker in the control?
What column type are you using in the database?
If you run your application in the debugger, what value do you see before you store it in the database?
If you run a query against the database in the relevant admin tool, does that show a time?

Categories