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

Insert default values in gridtemplate editmode=popup

1 Answer 78 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Harald
Top achievements
Rank 1
Harald asked on 21 Jun 2016, 06:49 AM

Hallo,
when I am use radgrid editmode=popup with a web user controll with insert action the template was displayed with empty field (no datarecord was bound).
For a better useibility I want to preset the template fields with default values. But how can I do this? To set the fields in the user control has no affect becaus it would be overitten after bounding to the empty insert record.

Harald

1 Answer, 1 is accepted

Sort by
0
Eyup
Telerik team
answered on 24 Jun 2016, 04:44 AM
Hi Harald,

You can use the ItemDataBound event handler to achieve this requirement. Distinguish the edit form from the insert form:
http://docs.telerik.com/devtools/aspnet-ajax/controls/grid/data-editing/distinguish-edit-or-insert-mode
Copy Code
Copy Code
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
{
    if (e.Item.IsInEditMode)
    {
        GridEditableItem item = e.Item as GridEditableItem;
        if (item is IGridInsertItem)
        {
            // insert mode logic
        }
        else
        {
            // edit mode logic
        }
    }
}

And access the generated controls to set their initial value for user convenience:
http://docs.telerik.com/devtools/aspnet-ajax/controls/grid/rows/accessing-cells-and-rows#accessing-controls-in-editinsert-mode

I hope this will prove helpful.

Regards,
Eyup
Telerik
Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
Tags
Grid
Asked by
Harald
Top achievements
Rank 1
Answers by
Eyup
Telerik team
Share this question
or