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

Edit form - Usercontrol - DatatItem is null

1 Answer 77 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Mikael
Top achievements
Rank 1
Mikael asked on 09 Nov 2016, 11:14 AM

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 ?

1 Answer, 1 is accepted

Sort by
0
Eyup
Telerik team
answered on 14 Nov 2016, 08:56 AM
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.
Tags
Grid
Asked by
Mikael
Top achievements
Rank 1
Answers by
Eyup
Telerik team
Share this question
or