DatePicker's MinDate in Grid behaves differently when set from server and desgin modes

5 posts, 0 answers
  1. Donald
    Donald avatar
    7 posts
    Member since:
    Jun 2011

    Posted 30 Mar 2012 Link to this post

    I am using a Datepicker in a Grid and want to prevent users from selecting date beyond a MinDate.

    At first i tried to set it in the ItemDataBound event:



    If (TypeOf e.Item Is GridEditableItem) AndAlso (e.Item.IsInEditMode) Then
    Dim edititem As GridEditableItem = DirectCast(e.Item, GridEditableItem)
    Dim datpkr As RadDatePicker = DirectCast(edititem("DateUpdated").Controls(0), RadDatePicker)
    datpkr.MaxDate = DateTime.Today
    datpkr.MinDate =DateTime.Today.AddDays(-15)
    End If

    The issue with this is that the dates are still selectable but i get an "alert" icon in the datepicker box.. I would like the users to try to not select dates beyond mindate. (saves me writing validation code)
    I then tried hardcoding the mindate in desgin mode as shown below:


    <telerik:GridDateTimeColumn DataField="DateUpdated" HeaderText="DateUpdated"
      UniqueName="DateUpdated" PickerType="DatePicker" MinDate="03/01/2012" />

    when i did that, i was not able to select dates before the mindate, which is what i want to do.

    I really need to set the mindate from the server-side (ItemDataBound event) as the mindate would be set to another date field in the database table.
    is there a way to "not select dates" les than Mindate from the server side? Or am i doing something wrong?

    I did check the forum for a similar issue/solution but did not find something related.


    Am using Q1, 2012 version

  2. Donald
    Donald avatar
    7 posts
    Member since:
    Jun 2011

    Posted 02 Apr 2012 Link to this post

    sorry,figured a way out using it this way. (i was not using edititemtemplate)

    Bascially wanted users to select dates between DateUpdated and Today. Dates beyond that range are viewable but not selectable.

    <telerik:GridTemplateColumn HeaderText="Date Fixed" UniqueName="Date_Fixed"
         <telerik:RadDatePicker ID="dpDateFixed" runat="server" Skin="Hay" 
             MaxDate = '<%# DateTime.Now %>' MinDate='<%# Bind("DateUpdated", "{0:d}") %>' >
  3. Eyup
    Eyup avatar
    4074 posts

    Posted 02 Apr 2012 Link to this post

    Hi Donald,

    Thank you for contacting us.

    I'm glad that you solved your problem. Note that your first desired behavior (to access the auto-generated DatePicker dynamically) is also achievable. You just need to change slightly your code-behind:
    Protected Sub RadGrid1_ItemDataBound(sender As Object, e As GridItemEventArgs)Handles RadGrid1.ItemDataBound
        If TypeOf e.Item Is GridEditableItem AndAlso e.Item.IsInEditMode Then
            Dim editForm As GridEditableItem = DirectCast(e.Item, GridEditableItem)
            Dim myDatePicker As RadDatePicker = TryCast(editForm("MyDateField").Controls(0), RadDatePicker)
            myDatePicker.SelectedDate = DateTime.Now.AddDays(20)
            myDatePicker.SharedCalendar.RangeMinDate = DateTime.Now.AddDays(5)
        End If
    End Sub

    As you probably noticed, in order to declare a MinDate to the EditForm DatePicker, you need to access the generated SharedCalendar.

    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
  4. faishal
    faishal avatar
    1 posts
    Member since:
    Jul 2018

    Posted 26 Nov 2018 in reply to Eyup Link to this post

    please sent C# Code for the following issue
  5. Eyup
    Eyup avatar
    4074 posts

    Posted 28 Nov 2018 Link to this post

    Hello Faishal,

    Here is the C# version of the code:
    protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
        if (e.Item is GridEditableItem && e.Item.IsInEditMode)
            GridEditableItem editForm = (GridEditableItem)e.Item;
            RadDatePicker myDatePicker = editForm["MyDateField"].Controls[0] as RadDatePicker;
            myDatePicker.SelectedDate = DateTime.Now.AddDays(20);
            myDatePicker.SharedCalendar.RangeMinDate = DateTime.Now.AddDays(5);

    You can also check the following section:

    In addition, here is the Telerik converter which you can check in similar scenarios:

    I hope this will prove helpful.

    Progress Telerik
    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Back to Top