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

How Can I refrence a user control in rad grid EditCommand Event

1 Answer 81 Views
Grid
This is a migrated thread and some comments may be shown as answers.
hasan
Top achievements
Rank 1
hasan asked on 15 Dec 2008, 09:35 AM
i want to use user control in rad grid to insert and update actions
and i need to do some action in editcommand event.
i need to do some action on controls that i place in user control and i need to manipulate  this controls same binding to
the objectdatasource or etc.
but when create a variable in editcommand event of rad grid of that user control ,
this variable is null and i cant refer to this variable and controls on this variable .
please tel me how can i create a variable of this type and manipulate its controls?

protected void radgrid1_EditCommand(object source, GridCommandEventArgs e)
        {
     
            GridEditableItem editedItem = e.Item as GridEditFormItem;
            UserControl userControl = (UserControl)e.Item.FindControl(GridEditFormItem.EditFormUserControlID);
           // WHY userControl =NULL ??????
        }

1 Answer, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 1
answered on 15 Dec 2008, 10:37 AM
Hello Hasan,

You can access the UserControl and make changes to the controls inside the usercontrol in the ItemCreated event of the grid as the EditCommand is too early for the UserControl to be created. Check out the code below:
cs:
protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e) 
    { 
 
       if (e.Item is GridEditableItem && e.Item.IsInEditMode) 
        { 
            GridEditableItem editedItem = e.Item as GridEditableItem; 
            UserControl userControl = (UserControl)e.Item.FindControl(GridEditFormItem.EditFormUserControlID); 
            Button btn = (Button)userControl.FindControl("CancelButton"); 
            btn.Enabled=false
        } 
     } 

Thanks
Princy.




Tags
Grid
Asked by
hasan
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 1
Share this question
or