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

Adding Validator to EditMode InPlace RadGrid

8 Answers 550 Views
Grid
This is a migrated thread and some comments may be shown as answers.
J
Top achievements
Rank 1
J asked on 01 Apr 2010, 11:59 PM
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

8 Answers, 1 is accepted

Sort by
0
Accepted
Yavor
Telerik team
answered on 07 Apr 2010, 07:30 AM
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.
0
Vikram
Top achievements
Rank 1
answered on 13 Mar 2012, 06:55 PM
Can anyone please provide me a working sample/ article for this issue. 
0
Shinu
Top achievements
Rank 2
answered on 14 Mar 2012, 05:13 AM
Hello Vikram,

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

-Shinu.
0
Vikram
Top achievements
Rank 1
answered on 14 Mar 2012, 02:06 PM
Thanks a lot Shinu. I cant imagine I missed that section on the page.
0
Pete
Top achievements
Rank 1
answered on 14 Feb 2013, 04:52 PM
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);

}

0
Pete
Top achievements
Rank 1
answered on 14 Feb 2013, 05:02 PM
I found my probelms.  Sorry for the troulbe.
0
Michael
Top achievements
Rank 1
answered on 17 Jun 2013, 08:52 AM

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

0
Eyup
Telerik team
answered on 20 Jun 2013, 08:18 AM
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.
Tags
Grid
Asked by
J
Top achievements
Rank 1
Answers by
Yavor
Telerik team
Vikram
Top achievements
Rank 1
Shinu
Top achievements
Rank 2
Pete
Top achievements
Rank 1
Michael
Top achievements
Rank 1
Eyup
Telerik team
Share this question
or