Edit form - Usercontrol - DatatItem is null

2 posts, 0 answers
  1. Mikael
    Mikael avatar
    11 posts
    Member since:
    Mar 2013

    Posted 09 Nov 2016 Link to this post


    I have a RadGrid with EditFormType="WebUserControl". In my usercontrol I have a custom validator to check the value and allow to update or not.

    My problem is that  _dataItem is null on the CustomValidator_ServerValidate event.
    I try this code :

    public object DataItem
            return (object)ViewState["DataItem"];
            ViewState["DataItem"] = value;

    But even with ViewState DataItem is always null (in CustomValidator_ServerValidate event).

    Have you a solution ?

  2. Eyup
    Eyup avatar
    3962 posts

    Posted 14 Nov 2016 Link to this post

    Hello Mikael,

    Generally, the DataItem of the GridDataItem instance is present only when binding the item, for example ItemDataBound event handler. You can try to add this field name to the DataKeyNames collection and then access it during the validation logic in server-side:

    You can get the currently edited grid item from the UserControl page using this.NamingContainer as GridEditableItem.
    I hope this will prove helpful.

    Telerik by Progress
    Check out the new UI for ASP.NET Core, the most complete UI suite for ASP.NET Core development on the market, with 60+ tried-and-tested widgets, based on Kendo UI.
Back to Top