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

Compare validator for GridDateTimeColumn throws Object reference not set to an instance of an object

3 Answers 77 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Kevin
Top achievements
Rank 1
Kevin asked on 09 Feb 2010, 03:30 PM
Hello

I am using two GridDateTimeColumns with Time PickerControl, I am trying to add a compare validator to one of the controls to compare the time against another control however adding the compare validator to the griddatetimecolumn throws Object Reference not set to an instance of an object exception. Below is the code I am using

Protected Sub RadGridTransCalc_ItemCreated(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridItemEventArgs) Handles RadGridTransCalc.ItemCreated  
 
            If (TypeOf e.Item Is GridEditableItem AndAlso e.Item.IsInEditMode) Then  
                Dim item As GridEditableItem = CType(e.Item, GridEditableItem)  
                Dim editor As GridDateTimeColumnEditor = CType(item.EditManager.GetColumnEditor("END_TIME"), GridDateTimeColumnEditor)  
                Dim cell As TableCell = CType(editor.PickerControl.Parent, TableCell)  
                Dim validator As CompareValidator = New CompareValidator  
                editor.TextBoxControl.ID = "ID_for_validation" 
                validator.ControlToValidate = editor.PickerControl.ID  
                validator.ControlToCompare = "START_TIME" 
                validator.Operator = "GreaterThan" 
                validator.Type = ValidationDataType.Date  
                validator.ErrorMessage = "End time must be greater than start time" 
                cell.Controls.Add(validator)  
            End If  
 
End Sub 

 

On debugging I found that the following line is throwing the exception

 

Dim cell As TableCell = CType(editor.PickerControl.Parent, TableCell)  

does anyone had a similar issue ?? If so how did you solve it, Help!!!!!

Thanks,
Kevin

3 Answers, 1 is accepted

Sort by
0
Yavor
Telerik team
answered on 12 Feb 2010, 08:17 AM
Hi Kevin,

The best option to add the validator in this case would be to access the relevant cells of the edit form, as shown in the following article:

http://www.telerik.com/help/aspnet-ajax/grdaccessingcellsandrows.html

and add the validators there. Also, you can try altering the edit mode, to verify that the way the edit form is rendered is not influencing the code logic.
I hope this suggestion helps.

Best wishes,
Yavor
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
Ram
Top achievements
Rank 1
answered on 22 Sep 2010, 05:22 PM
Protected Sub RadGridTransCalc_ItemCreated(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridItemEventArgs) Handles RadGridTransCalc.ItemCreated  
 
            If (TypeOf e.Item Is GridEditableItem AndAlso e.Item.IsInEditMode) Then  
                Dim item As GridEditableItem = CType(e.Item, GridEditableItem)  
                Dim editor As GridDateTimeColumnEditor = CType(item.EditManager.GetColumnEditor("END_TIME"), GridDateTimeColumnEditor)  
                Dim cell As TableCell = CType(editor.PickerControl.Parent, TableCell)  
                Dim validator As CompareValidator = New CompareValidator  
                ---------------------->editor.TextBoxControl.ID = "ID_for_validation" 
                validator.ControlToValidate = editor.PickerControl.ID  
                validator.ControlToCompare = "START_TIME" 
                validator.Operator = "GreaterThan" 
                validator.Type = ValidationDataType.Date  
                validator.ErrorMessage = "End time must be greater than start time" 
                cell.Controls.Add(validator)  
            End If  
 
End Sub 

Comment out this line.  The Id for the TextBox "END_TIME" is already either defined exlicity if specified in the aspx file or it would have already been implicitly provided by ASP.Net.  I solved the same issue this way.

But a better way is to have a Template Column and specify the validator in the edit template and Un-Wire the ItemCreated event.  This saves the round trip to server to run this Item Created event.
0
Chris
Top achievements
Rank 1
answered on 03 Nov 2010, 11:53 PM
But a better way is to have a Template Column and specify the validator in the edit template and Un-Wire the ItemCreated event.  This saves the round trip to server to run this Item Created event.

I would like to do just that, and place the validator in the edit template.  However, if I place the validator in the End_Time edit template, I can't seem to access the Start_Time field from within the edit template.  I could put both fields in the same edit template, but I'd rather not because it displays the fields side-by-side instead of in separate rows like all the other fields and it doesn't display the title for the second field.  Is there a way to have a validator work across edit templates?
Tags
Grid
Asked by
Kevin
Top achievements
Rank 1
Answers by
Yavor
Telerik team
Ram
Top achievements
Rank 1
Chris
Top achievements
Rank 1
Share this question
or