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

Find grid editform user control from outside the item command method(s)

1 Answer 79 Views
Grid
This is a migrated thread and some comments may be shown as answers.
David Borneman
Top achievements
Rank 1
David Borneman asked on 13 Nov 2013, 10:52 PM
Hi Guys,

Having a heck of a time here. 

We have one client who has a grid (radGrid) in which all rows are always in edit mode, and it uses a edit form user control for its edit mode.

I am trying to add a "Update All" button on the main page (just above the grid). In the button click event I need to loop thru all rows of the grid, find the user control and call a method on the user control that will update its data. I expected I would just call the Update button click event directly.

Problem is, no matter how I try, I cannot "find" the user control. Here is what I have tried:

foreach (GridDataItem dataitem in rgReview.Items)
        {
            if (dataitem.ItemType == GridItemType.AlternatingItem || dataitem.ItemType == GridItemType.Item)
            {   
                GridEditableItem item = (GridEditableItem) dataitem;
                 
                radGridReviewsUserControl userControl = (radGridReviewsUserControl)item.FindControl(GridEditFormItem.EditFormUserControlID);
                 
                string test = "";
 
                radGridReviewsUserControl uc = FindControl<radGridReviewsUserControl>(dataitem.Controls);
 
             }
        }

Notice I tried FindControl as well as a custom recursive FindControl method, and I have iterated thru the objects in debug mode and can find the user control nowhere. Am sure im close.. but just can't find the darn things :(

Can anyone give me a kick in the right direction?

Thanks,

Dave

1 Answer, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 1
answered on 14 Nov 2013, 08:05 AM
Hi David,

Please try the following code snippet. I have added an UpdateAll button outside the RadGrid and on its Click event i have accessed the UserControl EditForm.

C#:
protected void UpdateAll_Click(object sender, EventArgs e)
{
    foreach (GridDataItem item in RadGrid1.EditItems)
    {
        GridEditableItem edititem = (GridEditableItem)item.EditFormItem;
        UserControl MyUserControl = edititem.FindControl(GridEditFormItem.EditFormUserControlID) as UserControl;      
       //Access the EditForm controls
        RadTextBox radtxt = (RadTextBox)MyUserControl.FindControl("RadTextBoxID");
        string val = radtxt.Text;
        edititem.Edit = false; // Close the EditForms
        //Code to Update        
    }
}

Thanks,
Princy
Tags
Grid
Asked by
David Borneman
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 1
Share this question
or