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
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
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
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
Hi Peter,
Thank you, it works as expected...
V.