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

User Control IN Edit Form

1 Answer 60 Views
Grid
This is a migrated thread and some comments may be shown as answers.
J. David
Top achievements
Rank 1
J. David asked on 16 Feb 2011, 10:37 PM
Hi all,

We are implementing a RadGrid with a templated edit form.  We've placed a custom user control within the edit form template, like this:

<EditFormSettings EditFormType="Template" >
<FormStyle 
CssClass="GridForm"></FormStyle>
<FormTemplate>
<uc:UserRights 
ID="urEditForm" 
    UserID='<%# (Container is GridEditFormInsertItem) ? 0 : 
DataBinder.Eval(Container.DataItem,"ID") %>'  
    runat="server"/>
</FormTemplate>
</EditFormSettings>

As you can see, we've set it up so that the user control's UserID property is set to 0 when inserting, or to the actual value if editing.

Here's what we want to happen:

  • User control's ID is initially set to 0 when first opening the insert form.
  • When the insert action is performed, get the DataKey value from the inserted row (int Identity).
  • Re-set the control's UserID property to that DataKey value
  • Call the Update public method on the control.

My question is: what event can I hook that will provide me both access to the identity column value of the newly inserted item AND still let me trigger the public method on my user control so that it can update what it needs to update?

(There is much more to the form than simply the user control.  We are using mostly databound controls on the form template.  This user control is somewhat more complex and needs to be reusable, which is why we chose to compartmentalize it into its own control.)

Thanks!

1 Answer, 1 is accepted

Sort by
0
Veli
Telerik team
answered on 21 Feb 2011, 10:36 AM
Hello J. David,

The event that you need is ItemCommand and the command name you should look for is PerformInsert:

protected void RadGrid1_ItemCommand(object sender, GridCommandEventArgs e)
{
    if(e.CommandName == RadGrid.PerformInsertCommandName)
    {
        var editForm = e.Item.FindControl("urEditForm");
        //...
    }
}

Alternatively, you can use the InsertCommand event in RadGrid. It is fired for the same purpose at the same point.


Regards,
Veli
the Telerik team
Tags
Grid
Asked by
J. David
Top achievements
Rank 1
Answers by
Veli
Telerik team
Share this question
or