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

[Solved] How to loop through all controls inside Edit Form Template

1 Answer 620 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Zinoviy Margovskiy
Top achievements
Rank 1
Zinoviy Margovskiy asked on 08 Oct 2009, 09:04 PM
Hi Telerik,

I have a Radgrid with EditForm of type "Template".

On Server side at one point I need to traverse through all controls inside the Edit Form  template and their values.
Usually to get a reference to a control I do something like:
         
RadComboBox cntrlDDLhippingAccountType = null
cntrlDDLhippingAccountType = (RadGrid1.MasterTableView.GetItems(GridItemType.EditFormItem)[0]).FindControl("ddlID"as RadComboBox; 
 
 
Since, I need to reference all of the controls this time I tried to do the following:
       foreach (Control c in (RadGrid1.MasterTableView.GetItems(GridItemType.EditFormItem)[0]).Controls) 
        { 
            if (c is RadInputControl) 
            { 
                ((RadInputControl)c).Text = String.Empty; 
            } 
            else if (c is RadComboBox) 
            { 
                ((RadComboBox)c).SelectedIndex = 0; 
            } 
        } 

But this did not work, because Controls collection returns only EditFormTableCell control(s).
So the question is how can I Loop through all editable controls inside Edit Form template and set their values.

1 Answer, 1 is accepted

Sort by
0
Sebastian
Telerik team
answered on 09 Oct 2009, 10:27 AM
Hello Zinoviy,

You need to reference the Controls of the corresponding GridEditFormItem's EditFormCell to traverse the editors in the FormTemplate custom edit form. Hence your code should be modified as follows:

foreach (Control c in ((RadGrid1.MasterTableView.GetItems(GridItemType.EditFormItem)[0] as GridEditFormItem).EditFormCell).Controls)  
   {  
       if (c is RadInputControl)  
       {  
           ((RadInputControl)c).Text = String.Empty;  
       }  
       else if (c is RadComboBox)  
       {  
           ((RadComboBox)c).SelectedIndex = 0;  
       }  
   }  

Best regards,
Sebastian
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
Grid
Asked by
Zinoviy Margovskiy
Top achievements
Rank 1
Answers by
Sebastian
Telerik team
Share this question
or