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

Add a new row : be sure all the fields were filled

7 Answers 66 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Adigard
Top achievements
Rank 1
Adigard asked on 06 Oct 2011, 01:03 PM
Greetings,

i use a RadGrid with insert/edit/delete functionalities.
I would like to be sure the user fills all the fields when he tries to insert a new row / update a row

how can i manage to do this ?
thank you in advance!

7 Answers, 1 is accepted

Sort by
0
Accepted
Jayesh Goyani
Top achievements
Rank 2
answered on 06 Oct 2011, 01:50 PM
Hello,

protected void rgQueue_ItemCreated(object sender, GridItemEventArgs e)
       {
           if (e.Item is GridEditableItem && e.Item.IsInEditMode)
           {
               GridEditableItem item = e.Item as GridEditableItem;
                  
               //Find the cell and the item to validate
               GridTextBoxColumnEditor sorteditor = (GridTextBoxColumnEditor)item.EditManager.GetColumnEditor("Column1");
               TableCell cell = (TableCell)sorteditor.TextBoxControl.Parent;
               RequiredFieldValidator validator = new RequiredFieldValidator();
               sorteditor.TextBoxControl.ID = "ID_for_validation";
               validator.ControlToValidate = sorteditor.TextBoxControl.ID;
               validator.ErrorMessage = "*Required";
               validator.ForeColor = Color.Red;
               validator.Display = ValidatorDisplay.Dynamic;
               cell.Controls.Add(validator);

let me know if any concern.

Thanks,
Jayesh Goyani
0
Adigard
Top achievements
Rank 1
answered on 06 Oct 2011, 02:06 PM
Hello,

It looks to be what i'm looking for but i don't really understand your code... :s
What am i supposed to put instead of Column1
Thank you for your help anyway!
0
Adigard
Top achievements
Rank 1
answered on 06 Oct 2011, 02:14 PM
No!
I now understand
it is perfectly working!
thanks
0
Adigard
Top achievements
Rank 1
answered on 07 Oct 2011, 09:46 AM
Just a last question :


It is not working for a GridDateTimeColumn. I tried to make some changes but it is not working


do you find the error(s)?

                GridDateTimeColumnEditor Debut = (GridDateTimeColumnEditor)item.EditManager.GetColumnEditor("debut");
                TableCell CellDebut = (TableCell)Debut.PickerControl.Parent;
                RequiredFieldValidator DebutValidator = new RequiredFieldValidator();
                Debut.PickerControl.ID = "ID_for_DebutValidator";
                DebutValidator.ControlToValidate = Debut.PickerControl.ID;
                DebutValidator.ErrorMessage = "*NĂ©cessaire";
                DebutValidator.ForeColor = Color.Red;
                DebutValidator.Display = ValidatorDisplay.Dynamic;
                CellDebut.Controls.Add(DebutValidator);


Thank you in advance!
0
Adigard
Top achievements
Rank 1
answered on 07 Oct 2011, 04:26 PM
Can anyone help me ? :s
0
Accepted
Jayesh Goyani
Top achievements
Rank 2
answered on 07 Oct 2011, 06:16 PM
Hello,

Sorry for late reply,

<telerik:GridDateTimeColumn DataField="Cdate" ColumnEditorID="Column1" UniqueName="Column1">
............
...........
</telerik:RadGrid>
        <telerik:GridDateTimeColumnEditor ID="Column1" runat="server">
        </telerik:GridDateTimeColumnEditor>

if (e.Item is GridEditableItem && e.Item.IsInEditMode)
           {
               GridDateTimeColumnEditor columnEditor =
                   ((GridEditableItem)e.Item).EditManager.GetColumnEditor("Column1") as GridDateTimeColumnEditor;
 
               TableCell cell = (TableCell)columnEditor.PickerControl.Parent;
 
               RequiredFieldValidator validator = new RequiredFieldValidator();
               validator.ID = "RequiredFieldValidator1";
               validator.ControlToValidate = columnEditor.PickerControl.ID;
               validator.ErrorMessage = "*";
               cell.Controls.Add(validator);
           }

let me know if any concern.

Thanks,
Jayesh Goyani
0
Adigard
Top achievements
Rank 1
answered on 10 Oct 2011, 09:34 AM

Thanks a lot !
Tags
Grid
Asked by
Adigard
Top achievements
Rank 1
Answers by
Jayesh Goyani
Top achievements
Rank 2
Adigard
Top achievements
Rank 1
Share this question
or