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

Revisiting passing parameter to User Control Edit form when inserting

1 Answer 93 Views
Grid
This is a migrated thread and some comments may be shown as answers.
neebs
Top achievements
Rank 2
neebs asked on 02 Aug 2010, 07:36 PM
Hi,

I am struggling with how to pass a context variable to the insert logic in a user control edit form when Add a new Row is selected in a grid. The example I'm modelling this after is here:

http://demos.telerik.com/aspnet-ajax/grid/examples/dataediting/usercontroleditform/defaultcs.aspx

However on the DataBinding event of the user control for GridInsertionObject, I need to get one variable from the parent form, which is the ID of a row in a related table, which is required on insert to tie the inserted row to its parent. I've tried the mechanism here:

http://www.telerik.com/help/aspnet-ajax/grdinsertingvaluesusercontrolformtemplate.html

but that doesn't work. In the end, I store the ID I need in a session variable, but I'm not happy with that approach. Is there a simple way to do what I need to do?

Thanks, Steve

1 Answer, 1 is accepted

Sort by
0
Veli
Telerik team
answered on 06 Aug 2010, 07:10 AM
Hi neebs,

You can use RadGrid's ItemCreated or ItemDataBound event to reference the user control by ID and pass it any value you need:

protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
{
    if (e.Item is GridEditFormInsertItem && e.Item.IsInEditMode)
    {
        GridEditFormInsertItem insertItem = (GridEditFormInsertItem)e.Item;
        Control editFormControl = insertItem.FindControl(GridEditFormItem.EditFormUserControlID);
        //editFormControl now references your user control
        //you can pass it any value you need here
    }
}


Regards,
Veli
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
Grid
Asked by
neebs
Top achievements
Rank 2
Answers by
Veli
Telerik team
Share this question
or