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

[Solved] Validation Of MasterTableViewEditFormControls

4 Answers 112 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jon Adkins
Top achievements
Rank 2
Jon Adkins asked on 05 Aug 2009, 04:35 PM
All,

I currently have controls inside of a custom template that need to pass a strict validation process. For instance, there are two datetime pickers within the Template whose values need to be passed to a custom validation function. The problem that I am getting is how to pass those values to say the following customvalidator servervalidate routine. I seem to only be able to reference the items in one of the radgrid commands as shown below:
Protected Sub RadGrid2_UpdateCommand(ByVal source As ObjectByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles RadGrid2.UpdateCommand  
        If TypeOf e.Item Is GridEditableItem Then 
            Dim editedItem As GridEditFormItem = CType(e.Item, GridEditFormItem)  
            Dim StartTime As RadDateTimePicker = CType(editedItem.FindControl("RadDateTimePickerStart"), RadDateTimePicker)  
 
            Dim EndTime As RadDateTimePicker = CType(editedItem.FindControl("RadDateTimePickerEnd"), RadDateTimePicker)  
            Dim LeaveType As RadComboBox = CType(editedItem.FindControl("drpleavetype"), RadComboBox)  
            Dim LeaveRequest_Fkey As Label = CType(editedItem.FindControl("lblid"), Label)  
                          
 
 
 
 
 
 
        End If 

I need to be able to reference these values in the custom validator event as shown below:
Private Sub HoursPositiveValidator_ServerValidate(ByVal source As ObjectByVal args As System.Web.UI.WebControls.ServerValidateEventArgs) Handles HoursPositiveValidator.ServerValidate  
 

 

'Create variable to hold instance of validation return array.

 

 

Dim ReturnArray = LeaveClass.CustomDateValidation(FirstGridDateTimePicker.selectedvalue, SecondGridDateTimePicker.selectedvalue)

 

    If returnarray(0) = "False" then
        args.isvalid = false
    End If
End Sub 
Is it possible to reference these values outside of one of the radgrid events because a standard validation and custom validation will not fit my needs. Any help will be greatly appreciated.

Thanks,
Jonathan Adkins

4 Answers, 1 is accepted

Sort by
0
Veli
Telerik team
answered on 10 Aug 2009, 12:52 PM
Hello Jon,

I am not quite sure as to the reason you cannot use any standard or custom validator in ASP.NET, but the edited items can also be accessed outside RadGrid's ItemComand or UpdateCommand events. Your RadGrid's EditItems collection stores all items that are currently in edit mode. You can iterate over the collection and use FindControl() (if you are using FormTemplate editing) to access your custom editing controls.

Regards,
Veli
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Jon Adkins
Top achievements
Rank 2
answered on 11 Aug 2009, 03:09 PM
Veli,

Thanks for the response. Could you possible show me a code sample of what you mean. I would greatly appreciate it. Thanks again for all of the help.

Thanks,
Jonathan Adkins
0
Shinu
Top achievements
Rank 2
answered on 12 Aug 2009, 07:32 AM
Hi Jon,

You may loop through the Grid rows in edit mode and hence access the controls from the  EditFormTemplate as shown below.

VB:
 
 
    Protected Sub CustomValidator1_ServerValidate(ByVal source As ObjectByVal args As ServerValidateEventArgs) 
        For Each Item As GridDataItem In RadGrid1.EditItems 
            Dim picker1 As RadDatePicker = DirectCast(Item.EditFormItem.FindControl("RadDatePicker1"), RadDatePicker) 
            Dim selectedDate As DateTime = DirectCast(picker1.SelectedDate, DateTime) 
        Next 
    End Sub 
 


Regards
Shinu
0
Veli
Telerik team
answered on 12 Aug 2009, 01:25 PM
Hi Jon,

In case you use auto-generated grid column editors and do not know the ID of your editor controls:

Protected Sub Button1_Click(ByVal source As ObjectByVal e As EventArgs) Handles Button1.Click 
        For Each item As GridItem In RadGrid1.EditItems 
            If TypeOf item Is GridDataItem Then 
                Dim dataItem As GridDataItem = DirectCast(item, GridDataItem) 
                Dim editor As GridTextBoxColumnEditor = DirectCast(dataItem.EditFormItem, GridEditFormItem).EditManager.GetColumnEditor("UserName"
                Results.Controls.Add(New LiteralControl(editor.Text + "<br />")) 
            End If 
        Next 
    End Sub 

The above code iterates over all data items in the edited items collection, gets their EditFormItems and finds the column editor for grid column with unique name UserName. After converting it to the editor of the appropriate type (GridTextBoxColumnEditor for GridBoundColumns), you can retrieve the editor's Text property.

Greetings,
Veli
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
Grid
Asked by
Jon Adkins
Top achievements
Rank 2
Answers by
Veli
Telerik team
Jon Adkins
Top achievements
Rank 2
Shinu
Top achievements
Rank 2
Share this question
or