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

Validation to DateTime column in radgrid

17 Answers 651 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jack
Top achievements
Rank 1
Jack asked on 05 Sep 2008, 11:46 AM
Hi,

I have a RadGrid with GridDateTimeColumn as below.

<rad:GridDateTimeColumn DataField="Date1" UniqueName="Date1" EditFormColumnIndex="0" DataFormatString="{0:d}" >
</rad:GridDateTimeColumn>   

How can i check whether the entered date by user in the dateinput textbox is greater than or equal to todays date?Note user enters the date value instead of selecting from the datepicker

How can i have validations to the column during inserting and updating a record?

Regards

Jack

17 Answers, 1 is accepted

Sort by
0
Rosen
Telerik team
answered on 05 Sep 2008, 03:15 PM
Hi Jack,

You can use CompareValidator in order to validate the entered date. Similar to this:
protected void RadGrid_ItemCreated(object sender, GridItemEventArgs e)  
    {  
        if (e.Item is GridEditableItem && e.Item.IsInEditMode)  
        {  
            GridDateTimeColumnEditor columnEditor =  
                ((GridEditableItem) e.Item).EditManager.GetColumnEditor("Date1"as GridDateTimeColumnEditor;  
 
            TableCell cell = (TableCell) columnEditor.PickerControl.Parent;  
 
            CompareValidator compareValidator = new CompareValidator();  
            compareValidator.ID = "compareValidator";  
            compareValidator.ControlToValidate = columnEditor.PickerControl.ID;  
            compareValidator.Operator = ValidationCompareOperator.GreaterThanEqual;  
            compareValidator.Type = ValidationDataType.Date;  
            compareValidator.ErrorMessage = "*";  
            compareValidator.ValueToCompare = DateTime.Now.ToShortDateString();  
            cell.Controls.Add(compareValidator);  
        }  
    } 

Information about how to add validators to RadGrid columns can be found in this help article as in this live demo here.

Greetings,
Rosen
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
ravikiran jogu
Top achievements
Rank 1
answered on 11 Nov 2009, 04:39 PM
Hi, I tried this and this does not work, is there anything I need to change in the aspx page?

<

 

telerik:GridDateTimeColumn

 

 

UniqueName="ExpiryDateTime"

 

 

DataField="ExpiryDateTime"

 

 

DataFormatString="{0:MM/dd/yyyy}"

 

 

HeaderText="Expiration"

 

 

PickerType="DatePicker"

 

 

HeaderStyle-Width="18%"

 

 

/>

 

is all I have right now inside the grid.

Thanks
0
Iana Tsolova
Telerik team
answered on 16 Nov 2009, 09:57 AM
Hello,

Please review the following online resources on RadGrid validation and and make sure you are following the description and samples provided there in order to achieve your goal:
http://www.telerik.com/help/aspnet-ajax/grdvalidation.html
http://demos.telerik.com/aspnet-ajax/grid/examples/dataediting/validation/defaultcs.aspx

Give it a try and let me know if further issues arise.

Sincerely yours,
Iana
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Krish Singh
Top achievements
Rank 1
answered on 04 Mar 2010, 05:25 AM
Hi every one,

Is there any way to validate the

<telerik:GridDateTimeColumn UniqueName="fromDate" PickerType="DatePicker" HeaderText="From Date"
DataField="fromDate"><ItemStyle Width="80px" /></telerik:GridDateTimeColumn>
                           
<telerik:GridDateTimeColumn UniqueName="toDate" PickerType="DatePicker" HeaderText="To Date"
DataField="toDate"><ItemStyle Width="80px" /> </telerik:GridDateTimeColumn>

GridDateTimeColumn to Require Field Validation and Compare Validation.  (for example a datetime field generates error if the user enters something else).

Thanks

Krish
0
Iana Tsolova
Telerik team
answered on 04 Mar 2010, 12:40 PM
Hello krish,

You can add the desired validators to the edit fields in RadGrid by handling the grid ItemCreated event as shown here.

All the best,
Iana
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Mina Jeffrey
Top achievements
Rank 1
answered on 19 Jul 2010, 04:43 PM
hii all i want to display  a time coulm like 12:30 am in a rad grid column and i can't can anyone help me in that ?
0
Iana Tsolova
Telerik team
answered on 22 Jul 2010, 10:45 AM
Hello Mina,

Try using the GridDateTimeColumn for your purpose. You need to set the PickerType to TimePicker.
For more information on the grid column types, check this online demo.

All the best,
Iana
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Pams
Top achievements
Rank 1
answered on 27 Oct 2010, 03:41 PM
I tried adding compare validator in the Item Created event.
While adding a new record, When no value is selected in datetimecolumn. It is defaulty taking some value.(i think 01/01/0001 ).
and it is throwing error and the insert form is going. SO i had to reenter the values.
I want to display error saying to pick some datetime value.
Any help pls.
Thank you
0
Iana Tsolova
Telerik team
answered on 29 Oct 2010, 12:13 PM
Hi Pams,

You can add a RequiredFieldValidator in addition to the CompareValidator.

Sincerely yours,
Iana
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Milind Raje
Top achievements
Rank 1
answered on 21 Jan 2011, 06:05 PM
hi,
I looked at the online demo. However, the DateTime Column does display the warning icon but it still allows one to save the record if I typed invalid date say for example the letters "abcd" in the date input field manually. I want the update to display an error message and not allow the record to be saved. How to achieve this?
thanks
milind
0
Iana Tsolova
Telerik team
answered on 24 Jan 2011, 03:23 PM
Hi,

You should use a validator in addition to the date picker control. Can you confirm you tried it?

Kind regards,
Iana
the Telerik team
Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
0
Milind Raje
Top achievements
Rank 1
answered on 24 Jan 2011, 05:28 PM
hi,
I have tried using the validator like one of the examples. However, the validator doesn't cause the exception for the update button and allows me to save a blank date.
Thanks
milind
0
Iana Tsolova
Telerik team
answered on 25 Jan 2011, 04:53 PM
Hi Milind,

Can you share a runnable code so I can check it out?

Best wishes,
Iana
the Telerik team
Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
0
Milind Raje
Top achievements
Rank 1
answered on 25 Jan 2011, 08:05 PM

hi Lana,
I followed the example demo http://demos.telerik.com/aspnet-ajax/grid/examples/generalfeatures/columntypes/defaultcs.aspx

I just added the following code for my example. It seems the problem is that "ControlToValidate" is PickerControl which doesn't fire validation
However, if I set ControlToValidate = columnEditor.PickerControl.DateInput.ID I get runtime error. It still allows me to save the date as NULL when I click on the update button.
If you inspect the example in the link above, it allows you to save invalid date as NULL even though the picker control flags it as invalid.
thanks
milind

 

protected void RadGrid_ItemCreated(object sender, GridItemEventArgs e)   
    {   
        if (e.Item is GridEditableItem && e.Item.IsInEditMode)   
        {   
            GridDateTimeColumnEditor columnEditor =   
                ((GridEditableItem) e.Item).EditManager.GetColumnEditor("expirationDate") as GridDateTimeColumnEditor;   
    
            TableCell cell = (TableCell) columnEditor.PickerControl.Parent;   
    
            RegularExpressionValidator validator = new RegularExpressionValidator();   
            validator.ID = "expirationDateValidator";   
            validator.ControlToValidate = columnEditor.PickerControl.ID;   
            validator.ErrorMessage = "Invalid date";   
            // yyyy-mm-dd format
            validator.ValidationExpression = @"(19|20)\d\d[- /.](0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])";
            cell.Controls.Add(validator);   
        }   
    }  
0
Iana Tsolova
Telerik team
answered on 26 Jan 2011, 04:39 PM
Hello Jack,

Before setting the ControlToValidate property, try setting the ID of the PickerControl as this is done here for the TextBoxControl.

Regards,
Iana
the Telerik team
Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
0
Milind Raje
Top achievements
Rank 1
answered on 26 Jan 2011, 04:46 PM
hi Lana,
The example you described works for RequiredFieldValidator but doesn't work for date validation using RegularExpressionValidator.
thanks
milind
0
Iana Tsolova
Telerik team
answered on 31 Jan 2011, 03:20 PM
Hi Milind,

Please find the attached sample and let me know if it works and if I missed something out.

Best wishes,
Iana
the Telerik team
Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
Tags
Grid
Asked by
Jack
Top achievements
Rank 1
Answers by
Rosen
Telerik team
ravikiran jogu
Top achievements
Rank 1
Iana Tsolova
Telerik team
Krish Singh
Top achievements
Rank 1
Mina Jeffrey
Top achievements
Rank 1
Pams
Top achievements
Rank 1
Milind Raje
Top achievements
Rank 1
Share this question
or