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

How to change month names to month numbers

4 Answers 258 Views
MonthYearPicker
This is a migrated thread and some comments may be shown as answers.
Vasssek
Top achievements
Rank 1
Vasssek asked on 26 Feb 2020, 11:24 AM

Hi,

could somebody give me an advice, whether it's possible to have months in the same format as years ? I mean, now there are Jan. , Feb. .. and I want there only month numbers 01, 02.

And my second issue is how to change selected row value. Now, when I choose some month and year and click on OK button, there is January 2020. I need selected date in the format 01/2020, or 02/2020

Please, help me to solve this issues.

Regards

Vasssek

4 Answers, 1 is accepted

Sort by
0
Peter Milchev
Telerik team
answered on 02 Mar 2020, 08:46 AM

Hello Vasssek,

The format can be easily changed via the DateInput-DateFormat property: 

<telerik:RadMonthYearPicker ID="RadMonthYearPicker1" runat="server" DateInput-DateFormat="MM/yyyy"></telerik:RadMonthYearPicker>

Regards,
Peter Milchev
Progress Telerik

Get quickly onboarded and successful with UI for ASP.NET AJAX with the Virtual Classroom technical trainings, available to all active customers. Learn More.
0
Vasssek
Top achievements
Rank 1
answered on 02 Mar 2020, 10:22 AM

Hi,

your suggestion helps me to achieve second part of my previous thread :-). But how to change months names to months numbers in calendar popup, too ?

Regards

0
Accepted
Peter Milchev
Telerik team
answered on 04 Mar 2020, 02:20 PM

Hello Vasssek,

By default, the cells are populated with the abbreviated names of the picker's culture:

RadMonthYearPicker1.Culture.DateTimeFormat.AbbreviatedMonthNames;

The text of the cells can be changed in the ViewCellCreated event as demonstrated below:

<telerik:RadMonthYearPicker ID="RadMonthYearPicker1" runat="server" DateInput-DateFormat="MM/yyyy" OnInit="RadMonthYearPicker1_Init" OnViewCellCreated="RadMonthYearPicker1_ViewCellCreated">
</telerik:RadMonthYearPicker>

public Dictionary<string, string> AbbreviatedMonthNames;

protected void RadMonthYearPicker1_ViewCellCreated(object sender, Telerik.Web.UI.MonthYearViewCellCreatedEventArgs e)
{
    var ownerMonthYearPicker = sender as RadMonthYearPicker;
    if (e.Cell.CellType == Telerik.Web.UI.Calendar.MonthYearViewCellType.MonthCell)
    {
        var link = e.Cell.Controls[0] as HyperLink;
        link.Text = AbbreviatedMonthNames[link.Text];
    }
}
    
protected void RadMonthYearPicker1_Init(object sender, EventArgs e)
{
    // populate a new collection with values for month names
    var months = RadMonthYearPicker1.Culture.DateTimeFormat.AbbreviatedMonthNames;
    AbbreviatedMonthNames = new Dictionary<string, string>();
    for (int i = 0; i < months.Length; i++)
    {
        // Months will show up as "01", "02" instead of "Jan", "Feb"
        AbbreviatedMonthNames.Add(months[i], (i + 1).ToString("D2"));
    }
}

 

Regards,
Peter Milchev
Progress Telerik

Get quickly onboarded and successful with UI for ASP.NET AJAX with the Virtual Classroom technical trainings, available to all active customers. Learn More.
0
Vasssek
Top achievements
Rank 1
answered on 11 Mar 2020, 08:25 PM

Hi Peter,

 

Thank you, it works as expected...

V.

Tags
MonthYearPicker
Asked by
Vasssek
Top achievements
Rank 1
Answers by
Peter Milchev
Telerik team
Vasssek
Top achievements
Rank 1
Share this question
or