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

[Solved] Find UserControl in Edit command

1 Answer 109 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Le Anh Sang
Top achievements
Rank 1
Le Anh Sang asked on 09 Aug 2009, 12:46 AM
Hi all,
I have installed for Insert Command with code in ItemCommand event:
if (e.CommandName == RadGrid.InitInsertCommandName)
            {
                e.Canceled = true;
                e.Item.OwnerTableView.InsertItem();
                e.Item.OwnerTableView.IsItemInserted = true;
                GridEditableItem insertedItem = e.Item.OwnerTableView.GetInsertItem();
                String MyUserControlId = GridEditFormItem.EditFormUserControlID;
                UserControl userControl = insertedItem.FindControl(MyUserControlId) as UserControl;               
            }
this run well.

However, I don't know how to find my usercontrol when click Edit command. Please help me!

Thanks!

1 Answer, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 10 Aug 2009, 05:42 AM
Hello Le,

You can try accessing the UserControl in the ItemDataBound event rather than the ItemCommand event of the grid on clicking the EditButton as shown below:
c#:
protected void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e) 
    { 
        if (e.Item is GridEditableItem && e.Item.IsInEditMode) 
        { 
            GridEditableItem item = (GridEditableItem)e.Item; 
            UserControl usercontrol = (UserControl)item.FindControl(GridEditFormItem.EditFormUserControlID); 
 
        } 
    } 
 

Thanks
Princy.
Tags
Grid
Asked by
Le Anh Sang
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Share this question
or