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
Thanks in advance for any comments you wish to make,
Mark Breen
Ireland
1987 BMW R80 g/s
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