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

4 posts, 0 answers
  1. Robert Peter
    Robert Peter avatar
    6 posts
    Member since:
    Jun 2014

    Posted 19 Aug 2014 Link to this post

    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
  2. Kalin
    Admin
    Kalin avatar
    1208 posts

    Posted 20 Aug 2014 Link to this post

    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.
     
  3. UI for WPF is Visual Studio 2017 Ready
  4. Robert Peter
    Robert Peter avatar
    6 posts
    Member since:
    Jun 2014

    Posted 21 Aug 2014 in reply to Kalin Link to this post

    what is the problem with the first image? It is working fine, but then to make sure see the attachment.
  5. Kalin
    Admin
    Kalin avatar
    1208 posts

    Posted 22 Aug 2014 Link to this post

    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.
     
Back to Top