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

Validation on two or more controls in the radgrid

1 Answer 46 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Mark Breen
Top achievements
Rank 1
Mark Breen asked on 26 Jun 2010, 01:30 PM
Hello Guys,

I am using from the demos the code to validate a control within the grid and it works well.  I had to add a few additional lines to validate more than one control, and I wonder whether you would review it and tell me whether there is a better way to do it, or if this is optimum.

Thanks a lot, here is the code that works but may need improving.  You can see that I have taken the demo code and then added editor2, cell2, validator2 etc

            if (e.Item is GridEditableItem && e.Item.IsInEditMode) 
            { 
                GridEditableItem item = e.Item as GridEditableItem; 
                GridTextBoxColumnEditor editor = (GridTextBoxColumnEditor)item.EditManager.GetColumnEditor("PersonId"); 
                TableCell cell = (TableCell)editor.TextBoxControl.Parent; 
 
                RequiredFieldValidator validator = new RequiredFieldValidator(); 
                editor.TextBoxControl.ID = "ID_for_validation"
                validator.ControlToValidate = editor.TextBoxControl.ID; 
                validator.ErrorMessage = "You must enter a PersonId"
                cell.Controls.Add(validator); 
 
                GridTextBoxColumnEditor editor2 = (GridTextBoxColumnEditor)item.EditManager.GetColumnEditor("ContactWhere"); 
                TableCell cell2 = (TableCell)editor2.TextBoxControl.Parent; 
 
                RequiredFieldValidator validator2 = new RequiredFieldValidator(); 
                editor2.TextBoxControl.ID = "ID_for_validation2"
                validator2.ControlToValidate = editor2.TextBoxControl.ID; 
                validator2.ErrorMessage = "You must enter a H, C or M"
                cell2.Controls.Add(validator2); 
 

Thanks in advance for any comments you wish to make,

Mark Breen
Ireland
1987 BMW R80 g/s

1 Answer, 1 is accepted

Sort by
0
Tsvetoslav
Telerik team
answered on 30 Jun 2010, 12:48 PM
Hi Mark,

Your approach is completely valid and correct. The only thing you might consider is using the editor.ContainerControl property to access the table cell and add the validator control: editor.ContainerControl.Controls.Add(validator). However, it is equivalent to the code you have implemented with the only difference of saving you a few casts.

Hope this information helps.

Greetings,
Tsvetoslav
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
Tags
Grid
Asked by
Mark Breen
Top achievements
Rank 1
Answers by
Tsvetoslav
Telerik team
Share this question
or