Edit form - Usercontrol - DatatItem is null

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

    Posted 09 Nov Link to this post

    Hi,

    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
    {
        get
        {
            return (object)ViewState["DataItem"];
        }
        set
        {
            ViewState["DataItem"] = value;
        }
    }

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

    Have you a solution ?

  2. Eyup
    Admin
    Eyup avatar
    3012 posts

    Posted 14 Nov 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:
    http://docs.telerik.com/devtools/aspnet-ajax/controls/grid/rows/accessing-cells-and-rows#accessing-raw-field-data-and-key-values

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

    Regards,
    Eyup
    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top