MaxDate or MinDate for DatePicker in Grid ASP.Net Forms

Hello,

I'm working on ASP.Net Web Forms project.
I would like to set MaxDate and MinDate for DatePicker inside Grid row.  Can I do that?
If not, I want to add validation like between '01/01/1900' and DateTime.Now.

Could you give me an example for this?

Best Regards,
Yukiko

3 Replies

KM Kuralarasan Muthusamy Syncfusion Team July 19, 2018 12:45 PM UTC

Hi Yukiko, 

Thanks for contacting Syncfusion support. 

From you query we found that you want to set minDate and maxDate value for ejDatePicker while editing the grid. We have achieved your requirement by using grid column dateEditOptions property. Please refer the following code snippet: 

namespace ExportSample 
{ 
    public partial class GridFeatures : System.Web.UI.Page 
    { 
 
        protected void Page_Load(object sender, EventArgs e) 
        { 
            BindDataSource(); 
             
        } 
 
                   ....... 
 
        private void BindDataSource() 
        { 
            this.OrdersGrid.Columns[3].DateEditOptions = new DatePickerProperties() { MinDate = "01/01/1900", MaxDate = DateTime.Today }; 
        } 
    } 
} 

Refer the following link to know about dateEditOptions


This method is applied only for date which is selected by the datePicker. This method will not work while customer manually change the date in the input text box. If manually changed date is greater than maxDate, then max date will be saved in the grid. If it’s less than the minDate, then minDate will be saved in the Grid. In this case it does not show the any validation messages.  

If you want to set the validation for this case, then we suggest you to use custom validation method of the grid to achieve this requirement. Please refer the following code snippet: 

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server"> 
    <ej:Grid ID="OrdersGrid" runat="server" AllowPaging="true"> 
        <Columns> 
 
                         ...... 
 
            <ej:Column Field="OrderDate" HeaderText="Order Date" Width="90" Format="{0:MM/dd/yyyy}"> 
                <ValidationRule> 
                    <ej:KeyValue Key="customRegex" Value="true" />  
                </ValidationRule> 
            </ej:Column> 
        </Columns> 
    </ej:Grid> 
    <script type="text/javascript">  
    $(function () {         
        $.validator.addMethod("customRegex", function (value, element, params) {  
            var date1 = new Date(element.value); 
            var date2 = new Date("01/01/1900"); 
            var date3 = new Date(); 
            if (date1 > date2 && date1 < date3)  
                return true; 
            else return false;  
        }, "Please select the date between 01/01/1900 to today's date");  
    });  
</script>  
</asp:Content> 

In here we have handled this custom validation method in client side. Also you must need to refer the jquery validate script to use this validations in your project. We have prepared the sample by using both custom validation and dateEditOptions and that samples are downloadable from the below link, 



Refer the following link to know about column validation, custom validation : 



Please let us know if you need further assistance on this, 

Regards, 
Kuralarasan M. 



YI Yukiko Imazu July 19, 2018 06:03 PM UTC

Hi Kuralarasan,

Thank you for replying.
I solved my issue.

Thank you for your sample and explanation.

Best Regards,
Yukiko


KM Kuralarasan Muthusamy Syncfusion Team July 20, 2018 10:25 AM UTC

Hi Yukiko, 

We are happy to hear that your requirement has been achieved. Please let us know if you need further assistance. 

Regards, 
Kuralarasan M. 


Loader.
Up arrow icon