Adding Validator to EditMode InPlace RadGrid

9 posts, 1 answers
  1. J
    J avatar
    143 posts
    Member since:
    Jun 2006

    Posted 01 Apr 2010 Link to this post

    I have successfully added a RequiredFieldValidator on my grid, whose EditMode="InPlace":

    if ((e.Item is GridDataInsertItem) && e.Item.IsInEditMode)  
    {  
        //  Insert is clicked  
        GridEditableItem editedItem = e.Item as GridEditableItem;  
     
        GridDataItem dataItem = (GridDataItem)e.Item;  
     
        GridEditManager editMan = editedItem.EditManager;  
     
        GridDropDownListColumnEditor editor = editMan.GetColumnEditor("Id"as GridDropDownListColumnEditor;  
     
        RadComboBox dropDownList1 = editedItem["Id"].Controls[0] as RadComboBox;  
     
        TableCell cell = (TableCell)editor.ContainerControl;  
        //Declare the validator    
        RequiredFieldValidator rfv = new RequiredFieldValidator();  
     
        rfv.ControlToValidate = dropDownList1.ID;  
        rfv.ID = "valId";  
        rfv.ErrorMessage = @"<img src='Images/cautionIcon.png' class='Validation' />";  
     
        //Add the validator to the cell    
        cell.Controls.Add(rfv);    
     
        editor.ComboBoxControl.Skin = "MySkin";  
        editor.ComboBoxControl.EnableEmbeddedSkins = false;  
        editor.ComboBoxControl.DropDownWidth = Unit.Pixel(500);  
        editor.ComboBoxControl.Width = Unit.Pixel(380);  
     
        var erds = (from result in _s  
                 where !_Ds.Any(dto =>  
                     dto.Id == result.SystemID)  
                 select result).ToList<DTO>();  
     
        editor.DataSource = s;  
     
        editor.DataBind();  
    }  
    else if ((e.Item is GridEditableItem) && e.Item.IsInEditMode)  
    {  
        //  Edit is clicked  
        GridEditableItem editedItem = e.Item as GridEditableItem;  
     
        GridDataItem dataItem = (GridDataItem)e.Item;  
     
        DTO affected = (DTO)e.Item.DataItem;  
     
        GridEditManager editMan = editedItem.EditManager;  
     
        GridDropDownListColumnEditor editor = editMan.GetColumnEditor("Id"as GridDropDownListColumnEditor;  
     
        RadComboBox dropDownList1 = editedItem["Id"].Controls[0] as RadComboBox;  
     
        TableCell cell = (TableCell)editor.ContainerControl;  
        //Declare the validator    
        RequiredFieldValidator rfv = new RequiredFieldValidator();  
     
        rfv.ControlToValidate = dropDownList1.ID;  
        rfv.ID = "Id";  
        rfv.ErrorMessage = @"<img src='Images/cautionIcon.png' class='Validation' />";  
     
        editor.ComboBoxControl.Skin = "EPSS";  
        editor.ComboBoxControl.EnableEmbeddedSkins = false;  
        editor.ComboBoxControl.DropDownWidth = Unit.Pixel(500);  
        editor.ComboBoxControl.Width = Unit.Pixel(380);  
     
        var erds = (from result in _s  
                    where !_as.Any(dto =>  
                        dto.Id == result.SystemID && dto.Id != affected.Id)  
                    select result).ToList<DTOSystem>();  
     
        editor.DataSource = s;  
     
        editor.DataBind();  
     
        editor.SelectedValue = affected.Id.ToString();  
     

    I know my code is convaluted, but basically its correctly adding a RequiredFieldValidator when you click insert.  But not sure why, its now not putting an identical RequiredfieldValidator when I click 'Edit'?  I would think it would roughly be the same code.

    J
  2. Answer
    Yavor
    Admin
    Yavor avatar
    11 posts

    Posted 07 Apr 2010 Link to this post

    Hello J,

    For an edit operation, with Inplace editing, the item will be of type GridDataItem. Hence, you need to check

    if ((e.Item is GridDataItem) && e.Item.IsInEditMode)

    I hope this gets you started properly.

    Greetings,
    Yavor
    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Vikram
    Vikram avatar
    5 posts
    Member since:
    Sep 2012

    Posted 13 Mar 2012 Link to this post

    Can anyone please provide me a working sample/ article for this issue. 
  5. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 14 Mar 2012 Link to this post

    Hello Vikram,

    Check the following help documentation which explains more about this.
    Validation.

    -Shinu.
  6. Vikram
    Vikram avatar
    5 posts
    Member since:
    Sep 2012

    Posted 14 Mar 2012 Link to this post

    Thanks a lot Shinu. I cant imagine I missed that section on the page.
  7. Pete
    Pete avatar
    7 posts
    Member since:
    Feb 2013

    Posted 14 Feb 2013 Link to this post

    I'm trying to add Required and Range validators to a single inplace edit column with code below.  The first works, the second doesn't.  Any help is appreciated.

     

     

    if (e.Item is GridEditableItem && e.Item.IsInEditMode)

     

    {

     

     

    GridEditableItem editItem = (GridEditableItem)e.Item;

     

     

     

    GridTextBoxColumnEditor editor = (GridTextBoxColumnEditor)editItem.EditManager.GetColumnEditor("WaterCapacity");

     

     

     

    TableCell cell = (TableCell)editor.TextBoxControl.Parent;

     

     

     

    RequiredFieldValidator valReq = new RequiredFieldValidator();

     

    editor.TextBoxControl.ID =

     

    "ControlId";

     

    valReq.ControlToValidate = editor.TextBoxControl.ID;

    valReq.ErrorMessage =

     

    "Enter capacity 3,000 - 16,000";

     

    valReq.ForeColor = System.Drawing.

     

    Color.Red;

     

    cell.Controls.Add(valReq);

     

     

    RequiredFieldValidator valRange = new RequiredFieldValidator();

     

    valRange.ControlToValidate = editor.TextBoxControl.ID;

    valRange.ErrorMessage =

     

    "Enter capacity 3,000 - 16,000";

     

    valRange.ForeColor = System.Drawing.

     

    Color.Red;

     

    cell.Controls.Add(valRange);

    }

  8. Pete
    Pete avatar
    7 posts
    Member since:
    Feb 2013

    Posted 14 Feb 2013 Link to this post

    I found my probelms.  Sorry for the troulbe.
  9. Michael
    Michael avatar
    19 posts
    Member since:
    Jun 2012

    Posted 17 Jun 2013 Link to this post

    Hallo,

    when trying to add validatiogroups as explained in http://www.telerik.com/community/forums/aspnet-ajax/grid/radgrid-perform-validation-only-in-edit-or-insert-mode-and-not-both.aspx im experiencing the issue that in InPlace-Mode you cannot distinguish between an insert and edit Item by asking :

    if (e.Item is GridEditFormInsertItem)

    as it never is!
    Is ther an alternative Approach for InPlace- editing?

    Regards Michael

  10. Eyup
    Admin
    Eyup avatar
    3007 posts

    Posted 20 Jun 2013 Link to this post

    Hello Michael,

    In this case the item is of type GridDataInsertItem. You can use the approach demonstrated in the following article to achieve the requested functionality:
    http://www.telerik.com/help/aspnet-ajax/grid-distinguish-edit-insert-mode-on-itemcreated-itemdatabound.html

    Hope this helps.

    Regards,
    Eyup
    Telerik
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017