Chage TimeView by code

7 posts, 0 answers
  1. Dario
    Dario avatar
    61 posts
    Member since:
    Apr 2011

    Posted 07 Nov 2012 Link to this post

    Hi to all,
    I would:
    1. select an item by dropbox
    2. select a date, and by this auto-postback
    3. Into selected-changed event I would change timeview (starttime, endtime and interval)

    How can I do this?

  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 07 Nov 2012 Link to this post

    Hi Dario,

    I suppose you want to change the timeview (starttime, endtime and interval) in SelectedDateChanged Event. Here is the sample code that I tried.

    C#:
    protected void RadDateTimePicker1_SelectedDateChanged(object sender, Telerik.Web.UI.Calendar.SelectedDateChangedEventArgs e)
    {
     TimeSpan start = new TimeSpan(2, 0, 0);
     TimeSpan end = new TimeSpan(10, 0, 0);
     TimeSpan interval = new TimeSpan(2, 0, 0);
     RadDateTimePicker11.TimeView.StartTime = start;
     RadDateTimePicker11.TimeView.EndTime = end;
     RadDateTimePicker11.TimeView.Interval = interval;
    }

    Hope this helps.

    Thanks,
    Princy.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Dario
    Dario avatar
    61 posts
    Member since:
    Apr 2011

    Posted 08 Nov 2012 Link to this post

    I explain my situation:

    I have a RadCalendar controllo and RadDropBox.
    I have to select an item of RadDropBox, this item gives me some information (starttime, endtime and interval).
    After this I select a date on RadCalendar, this controlo has AutoPostBack = true.
    Into RadCalendar_SelectDateChanged (I don't remember if this is the name of this event), I must change properties of a RadDateTimePicker.

    I done this, but gives me a trange effect: I must click 2 times on RadCalendar because on first time I don't obtain a correctly configuration of RadDateTimePicker.

    I don't undestand why this...
  5. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 08 Nov 2012 Link to this post

    Hi Dario,

    Unfortunately I couldn't replicate the issue you are facing. Here is the full code that I tried based own your scenario which works as expected.

    ASPX:
    <telerik:RadComboBox ID="RadComboBox1"  runat="server" >
         <Items>
          <telerik:RadComboBoxItem Text="one" Value="1" />
          <telerik:RadComboBoxItem Text="two" Value="2" />
          <telerik:RadComboBoxItem Text="three" Value="3" />
         </Items>
    </telerik:RadComboBox>
    <telerik:RadCalendar ID="RadCalendar1" runat="server" AutoPostBack="true" onselectionchanged="RadCalendar1_SelectionChanged" >
    </telerik:RadCalendar>
    <telerik:RadDateTimePicker ID="RadDateTimePicker1"  runat="server" >
    </telerik:RadDateTimePicker>

    Please  provide your code if this doesn't helps.

    Thanks,
    Princy.
  6. Dario
    Dario avatar
    61 posts
    Member since:
    Apr 2011

    Posted 09 Nov 2012 Link to this post

    Ok thank you for support:

    RadCalendar_SelectionChanged(object sender, Telerik.Web.UI.Calendar.SelectedDatesEventArgs e)
    {
    //Set monday day relative to user selected date
                DateTime selezionato = e.SelectedDates.Count == 1 ? e.SelectedDates[0].Date : DateTime.Today;
                DayOfWeek giornoSettimanaleDiOggi = selezionato.DayOfWeek;
                DateTime lunedì = new DateTime();
     
                if (giornoSettimanaleDiOggi == DayOfWeek.Sunday)
                    lunedì = selezionato.AddDays(-6);
                else
                    lunedì = selezionato.AddDays((Convert.ToInt32(giornoSettimanaleDiOggi) - 1) * -1);
     
                RicercaRadCalendar.SelectedDate = lunedì;
     
    //After Change TimeView of RadDateTimePicker
      CustomTimeView MyItemSelected = ConvertValueToMyItemSelected(FieldDropDownList.SelectedValue);
       
      RadDateTimePicker.TimeView.StartTime = MyItemSelected.StartTime;
      RadDateTimePicker.TimeView.EndTime = MyItemSelected.EndTime;
      RadDateTimePicker.TimeView.Interval = MyItemSelected.Interval;
     
    }
     
    public class CustomTimeView
    {
      TimeSpan StartTime {get;set;}
      TimeSpan EndTime {get;set;}
      TimeSpan Interval {get;set;}
     [..]
    }
  7. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 12 Nov 2012 Link to this post

    Hi Dario,

    Try the following code to achieve your scenario.

    C#:
    public CustomTimeView ConvertValueToMyItemSelected(string value)
    {
        CustomTimeView data = new CustomTimeView();
        data.StartTime = new TimeSpan(2, 0, 0);
        data.EndTime = new TimeSpan(10, 0, 0);
        data.Interval = new TimeSpan(Convert.ToInt32(value), 0, 0);
        return data;
    }
    protected void  RadCalendar_SelectionChanged(object sender, Telerik.Web.UI.Calendar.SelectedDatesEventArgs e)
    {
        //Set monday day relative to user selected date
         DateTime selezionato = e.SelectedDates.Count == 1 ? e.SelectedDates[0].Date : DateTime.Today;
         DayOfWeek giornoSettimanaleDiOggi = selezionato.DayOfWeek;
         DateTime lunedì = new DateTime();
         if (giornoSettimanaleDiOggi == DayOfWeek.Sunday)
         lunedì = selezionato.AddDays(-6);
         else
         lunedì = selezionato.AddDays((Convert.ToInt32(giornoSettimanaleDiOggi) - 1) * -1);
         RicercaRadCalendar.SelectedDate = lunedì;
         //After Change TimeView of RadDateTimePicker
         CustomTimeView MyItemSelected = ConvertValueToMyItemSelected(FieldDropDownList.SelectedValue);
         RadDateTimePicker1.TimeView.StartTime = MyItemSelected.StartTime;
         RadDateTimePicker1.TimeView.EndTime = MyItemSelected.EndTime;
         RadDateTimePicker1.TimeView.Interval = MyItemSelected.Interval;
    }

    Thanks,
    Princy.
  8. Dario
    Dario avatar
    61 posts
    Member since:
    Apr 2011

    Posted 13 Nov 2012 Link to this post

    Thank you very much!
    I understud that my problem was the "selecting date" and forcing date to relative monday day.

    Infact, during this second select I'm creating strange environment.

    Then, I set this code only when e.SelectedDates[0] is Monday

    //After Change TimeView of RadDateTimePicker
         CustomTimeView MyItemSelected = ConvertValueToMyItemSelected(FieldDropDownList.SelectedValue);
         RadDateTimePicker1.TimeView.StartTime = MyItemSelected.StartTime;
         RadDateTimePicker1.TimeView.EndTime = MyItemSelected.EndTime;
         RadDateTimePicker1.TimeView.Interval = MyItemSelected.Interval;

    By this way it's ok!
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017