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

Validation on Update/ Insert with AutogenerateColumns=true

1 Answer 26 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Krutika
Top achievements
Rank 1
Krutika asked on 16 Nov 2012, 07:04 PM
How to achieve validation of required fields and datatype check when AutogenerateCoulmns is set ot TRUE?
I tried looknig at the demo, most of them use templates Asample proj might help thanks!

1 Answer, 1 is accepted

Sort by
0
Jayesh Goyani
Top achievements
Rank 2
answered on 17 Nov 2012, 02:10 PM
Hello,

protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
       {
           if (e.Item is GridEditableItem && e.Item.IsInEditMode)
           {
               GridEditableItem editedItem = e.Item as GridEditableItem;
               GridEditManager editMan = editedItem.EditManager;
 
               GridTextBoxColumnEditor editor = (GridTextBoxColumnEditor)(editMan.GetColumnEditor("Name")); // Name is datafield/columnunique name
               TableCell cell = (TableCell)(((Telerik.Web.UI.GridTextBoxColumnEditor)(editor))).TextBoxControl.Parent;
               TextBox txt = editor.TextBoxControl;
               RequiredFieldValidator validator1 = new RequiredFieldValidator();
               validator1.ID = "rf" + txt.ID;
               validator1.ControlToValidate = txt.ID;
               validator1.ErrorMessage = "Please provide value";
               cell.Controls.Add(validator1);
           }
       }


Thanks,
Jayesh Goyani
Tags
Grid
Asked by
Krutika
Top achievements
Rank 1
Answers by
Jayesh Goyani
Top achievements
Rank 2
Share this question
or