GridBoundColumn Validator issue

4 posts, 0 answers
  1. Michael Nagy
    Michael Nagy avatar
    18 posts
    Member since:
    May 2008

    Posted 23 Jan 2009 Link to this post

    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 .



  2. Daniel
    Admin
    Daniel avatar
    4945 posts

    Posted 26 Jan 2009 Link to this post

    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Michael Nagy
    Michael Nagy avatar
    18 posts
    Member since:
    May 2008

    Posted 27 Jan 2009 Link to this post

    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
  5. Daniel
    Admin
    Daniel avatar
    4945 posts

    Posted 27 Jan 2009 Link to this post

    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.
Back to Top