This is a migrated thread and some comments may be shown as answers.

How to pass value from datepicker when editing certain entry in a gridview?

3 Answers 155 Views
DatePicker
This is a migrated thread and some comments may be shown as answers.
Robert Peter
Top achievements
Rank 1
Robert Peter asked on 20 Aug 2014, 02:42 AM
How to pass value from datepicker when editing a existing entry in a gridview. For instance I have a column name ExpirationMonth with a cell data of AUG, and I want that to pass in a DatePicker Input, instead of seeing the watermark "Enter date". See the first Image.

The first image when editing a certain entry in a gridview, Aug does not show up in the ExpirationMonth, 2014 does not show up in Expiration Year.

Also when I add an entry still the same even it has a default value, set as
//for ExpirationMonth
DateTime.Now.ToString("MMM");
 
//for Expiration Year
DateTime.Now.ToString("yyyy");

But when I select a month for ExpirationMonth, month I selected appears in the DatePicker input. See the second Image.

What I did to show month and year in the Datepicker Input, here is the code snippet:
public CreditCardWindow()
    {
        InitializeComponent();
 
        CultureInfo cultureInfo = new CultureInfo("en-US");
        DateTimeFormatInfo dateTimeFormatInfo = new DateTimeFormatInfo();
        dateTimeFormatInfo.ShortDatePattern = "MMMM";
        cultureInfo.DateTimeFormat = dateTimeFormatInfo;
        dteExpirationMonth.Culture = cultureInfo;
        string dteMonth = dteExpirationMonth.SelectedValue.ToString();
        dteMonth.ToUpper();
 
        CultureInfo cultureInfo2 = new CultureInfo("en-US");
        DateTimeFormatInfo dateTimeFormatInfo2 = new DateTimeFormatInfo();
        dateTimeFormatInfo2.ShortDatePattern = "yyyy";
        cultureInfo2.DateTimeFormat = dateTimeFormatInfo2;
        dteExpirationYear.Culture = cultureInfo2;
 
 
    }


Regards,
Robert Peter Mansion

3 Answers, 1 is accepted

Sort by
0
Kalin
Telerik team
answered on 20 Aug 2014, 01:12 PM
Hi Robert,

There is a problem with the first of the attached image, could you please reattached again? It is not clear if you need to set the value of the DatePicker from a string or you need to get the visible string in the input field of the DatePicker? What I can suggest you would be to check the DateTimeText property of the control. By using it you would be able to get the current text or pass a string value which will be parsed by the control and selected. For example:

this.datePicker.DateTimeText = "Aug";

Hope this will help.

Regards,
Kalin
Telerik
 
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
 
0
Robert Peter
Top achievements
Rank 1
answered on 22 Aug 2014, 12:30 AM
what is the problem with the first image? It is working fine, but then to make sure see the attachment.
0
Kalin
Telerik team
answered on 22 Aug 2014, 11:35 AM
Hello Robert,

I tested the explained approach and was able to successfully set the month and year from the selected row of the GridView. For the year DatePicker you would also need to set the ParseExact property in order to correctly parse only year entered. Please check the attached project and let me know whether it helps.

I hope it will work for you.

Regards,
Kalin
Telerik
 
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
 
Tags
DatePicker
Asked by
Robert Peter
Top achievements
Rank 1
Answers by
Kalin
Telerik team
Robert Peter
Top achievements
Rank 1
Share this question
or