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

GridBoundColumn Validator issue

3 Answers 94 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Michael Nagy
Top achievements
Rank 2
Michael Nagy asked on 23 Jan 2009, 12:50 PM

Hello ,

I want to add some validates at bounded columns , I  tried hardly to let it work but I failed so please help me in this issue :-
first of all i have grid has 4 Bounded column
 <telerik:GridBoundColumn  DataField="EmployerName" HeaderText="Employer&nbsp;Name"  UniqueName="EmployerName"/>
 <telerik:GridBoundColumn DataField="Position" HeaderText="Position" UniqueName="Position" />
 <telerik:GridDateTimeColumn DataField="FromDT" HeaderText="From" UniqueName="FromDT" />
 <telerik:GridDateTimeColumn DataField="ToDT" HeaderText="To" UniqueName="ToDT"/>

I need to add 4 required validation on these column
I registered ItemCreated event and tried to add validations like that
    protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
    {

        if (e.Item is GridEditableItem && e.Item.IsInEditMode)
        {
            GridEditableItem item = e.Item as GridEditableItem;
            RequiredFieldValidator validator1 = new RequiredFieldValidator();
            validator1.ID = "validator1";
            validator1.ErrorMessage = " * " ;
            (item["EmployerName"].Controls[0] as TextBox).ID = item.ClientID + "_TextBox";
            validator1.ControlToValidate = (item["EmployerName"].Controls[0] as TextBox).ID;
            item["EmployerName"].Controls.Add(validator1);
        }
  }


Vaildators worked well but at insert or update event handler after called extract values method , I figured that the value for the EmployerName and Position columns was always equal null and other have values.

item.ExtractValues(newValues); // newValues["EmployerName"] , Although I entered value in the edit form

after that I tried to add the Vaildators at item data bound event but it is still the same and the values returned null also.

I think when I changed the id of the item[ColumnUniqueName].control[0] the extract item didn't work well .



3 Answers, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 26 Jan 2009, 05:28 PM
Hello Michael,

I answered the same question in another thread.

Let us know how you attached your ItemCreated event in order to give you to-the-point answer.

Regards,
Daniel
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Michael Nagy
Top achievements
Rank 2
answered on 27 Jan 2009, 08:54 AM
thanks Daniel  for your replay ,
  i register this event at page load

RadGrid1.NeedDataSource +=

new GridNeedDataSourceEventHandler(RadGrid1_NeedDataSource);

 

RadGrid1.UpdateCommand +=

new GridCommandEventHandler(RadGrid1_UpdateCommand);

 

RadGrid1.InsertCommand +=

new GridCommandEventHandler(RadGrid1_InsertCommand);

 

RadGrid1.DeleteCommand +=

new GridCommandEventHandler(RadGrid1_DeleteCommand);

 

RadGrid1.CreateColumnEditor +=

new GridCreateColumnEditorEventHandler(Radgrid1_CreateColumnEditor);

 

RadGrid1.ItemDataBound +=

new GridItemEventHandler(Radgrid1_ItemDataBound);

 

RadGrid1.ItemCommand +=

new GridCommandEventHandler(Radgrid1_ItemCommand);

 

RadGrid1.ItemCreated +=

new GridItemEventHandler(RadGrid1_ItemCreated);  /// this is what you need  ?

 



thiis is al event hanlder i have
0
Daniel
Telerik team
answered on 27 Jan 2009, 06:27 PM
Hello Michael,

Thank you for the provided code. It's exactly as I thought. Please attach your handler (ItemCreated) in the declaration of your RadGrid and let me know whether this helps.

Best regards,
Daniel
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
Grid
Asked by
Michael Nagy
Top achievements
Rank 2
Answers by
Daniel
Telerik team
Michael Nagy
Top achievements
Rank 2
Share this question
or