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

RadGrid GridDropDownColumn validations

2 Answers 118 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Rokk
Top achievements
Rank 1
Rokk asked on 26 May 2015, 09:42 AM

Hi,

 I'm quite new with asp and telerik components, so I need some help to figure this out:

 i'm trying to validate GridDropDownColumns that hold Combobox's and check is text area of combobox filled with value from dropdown.

 Now my problem is when I try to add custom validator in cs code side, it doesn't fire serverside validation. I don't want to add templatecollums to my grid if it's not necessary.

 in itemDataBound:

 

if (e.Item is GridEditableItem && e.Item.IsInEditMode)
{
 
            GridEditableItem item = e.Item as GridEditableItem;
 
            if(item["content"].Controls[0] is RadComboBox)
            {
 
                GridDropDownListColumnEditor editor = item.EditManager.GetColumnEditor("content") as GridDropDownListColumnEditor;
 
                TableCell cell = (TableCell)editor.ComboBoxControl.Parent;
                 
                   CustomValidator validator = new CustomValidator();
 
                validator.ServerValidate += new ServerValidateEventHandler(comboboxValidations_ServerValidate);
                validator.ValidationGroup = "comboGroup";
                validator.ErrorMessage = "!";
                validator.ValidateEmptyText = true;
 
                validator.ControlToValidate = editor.ComboBoxControl.ID;
                cell.Controls.Add(validator);
 
            }
}

2 Answers, 1 is accepted

Sort by
0
Accepted
Viktor Tachev
Telerik team
answered on 29 May 2015, 07:40 AM
Hi,

The logic you are using to add CustomValidator to the column is correct. However, it should be implemented in the ItemCreated event handler of RadGrid.  

Also, I noticed that the ValidationGroup property is set for the CustomValidator. Note that in order to trigger validation the control that triggers postback (e.g. a Button) should have the same ValidationGroup. Alternatively, you can remove the ValidationGroup property.

In case you would like additional information on adding validator controls to a grid column you would find the following article interesting.



Regards,
Viktor Tachev
Telerik
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 Feedback Portal and vote to affect the priority of the items
0
Rokk
Top achievements
Rank 1
answered on 29 May 2015, 09:27 AM

Thanks Viktor.

I finally got it working with your instructions.

 

Tags
Grid
Asked by
Rokk
Top achievements
Rank 1
Answers by
Viktor Tachev
Telerik team
Rokk
Top achievements
Rank 1
Share this question
or