简体   繁体   中英

Column validation in RadGrid when EditMode=InPlace

I have a very annoying problem with validating a column in a RadGrid. In edit mode(IN PLACE) I want a column to be validated when pressing image button for submit.

The problem is that my GridTextBoxColumnEditor is moved upwards just to make space for the error message IF the validation fails. So when the edit form is loaded the controls have different vertical position. I think it should be possible to move the GridTextBoxColumnEditor upwards and show the message ONLY if the validation fails. Then all the controls get the right alignment. I have tried to create the validator in the InsertCommand event but that didn't work. Down below you can see my code:

protected void gridReports_ItemCreated(object sender, GridItemEventArgs e)
{
    if (e.Item is GridEditableItem && e.Item.IsInEditMode)
    {
        GridEditableItem editedItem = e.Item as GridEditableItem;
        GridTextBoxColumnEditor editor = null;

        if (editedItem["description"].Text == " ")
        {
            editor = (GridTextBoxColumnEditor)editedItem.EditManager.GetColumnEditor("description");
            TableCell cell = (TableCell)editor.TextBoxControl.Parent;
            RequiredFieldValidator validator = new RequiredFieldValidator();
            validator.ControlToValidate = editor.TextBoxControl.ID;
            validator.ErrorMessage = "Field is mandatory!";
            cell.Controls.Add(validator);
        }

Do you guys have any suggestions?

如果将验证器的Display属性设置为“动态”,则可以解决您的问题。

validator.Display = ValidatorDisplay.Dynamic;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM