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

Date Picker for Selecting Months - Possible?

2 Answers 203 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Johnathan
Top achievements
Rank 1
Johnathan asked on 25 Aug 2010, 11:53 AM
Hi

I am using the grid control to display data from a database. The first column is always a date eg

Date (DD/MM/YY)    QTY
1/1/2010                    1
1/2/2010                    5
1/3/2010                    7 etc

All of my dates actually represent months and I display them as Jan-10, Feb-10, Mar-10 etc but store them in the database as a full date on the first day of the month

My grid has the ability to add records which I do manually in code called from the insert grid event. I get the value of the date picker with

Dim

 

 

InsertedDate = TryCast(InsertedItem("mydatecolumn").Controls(0), RadDatePicker).SelectedDate

 


As there is not a month / year picker I'd like to use the date picker but if the user picks say "13/3/2010" then I would like to change this immediatley to "1/3/2010".

Is this possible, if so can you give me some pointers?

Thanks

Johnathan

2 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 26 Aug 2010, 08:52 AM
Hello Johnathan,

In order to achieve this attach an 'OnDateSelected' client event to RadDatePicker. In this event handler change the date in selected date of Datepicker to first day of month. Check out the following code snippet.
 
C#:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
   {
      if (e.Item is GridEditFormInsertItem && e.Item.OwnerTableView.IsItemInserted)
       {
           GridEditFormInsertItem insertItem = (GridEditFormInsertItem)e.Item;
           RadDatePicker dtPicker = (RadDatePicker)insertItem["mydatecolumn"].Controls[0];
           dtPicker.SharedCalendar.EnableMultiSelect = false;
           dtPicker.ClientEvents.OnDateSelected = "OnDateSelected";   
       }
   }

Java Script:
<script type="text/javascript">
      function OnDateSelected(sender, args) {
        var year = sender._calendar.get_selectedDates()[0][0];
        var month = sender._calendar.get_selectedDates()[0][1];
        var date = 1;
        var dateString = month + "/" + date + "/" + year;
        var myDate = new Date(dateString);
        sender.set_selectedDate(myDate);
    }
</script>

Thanks,
Princy.
0
Johnathan
Top achievements
Rank 1
answered on 26 Aug 2010, 09:16 AM
Hi Princy

Thanks for your time. That's spot on!

Regards

Johnathan
Tags
Grid
Asked by
Johnathan
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Johnathan
Top achievements
Rank 1
Share this question
or