Skip to content

DevExpress-Examples/asp-net-web-forms-form-layout-find-item-and-access-controls

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Form Layout for ASP.NET Web Forms - How to find an item and access nested controls

This example demonstrates how to find a layout item by its name and assign a value to a nested control.

FormLayout Items

Overview

Create the Form Layout control, add item and group objects, and specify their Name properties.

<dx:LayoutGroup Caption="Group1" Name="Group01">
    <Items>
        <dx:LayoutItem Caption="LayoutItem011" Name="LayoutItem011">
            <LayoutItemNestedControlCollection>
                <dx:LayoutItemNestedControlContainer ID="layoutContainer1" runat="server">
                    <dx:ASPxTextBox ID="ASPxTextBox1" runat="server" Width="170px" />
                </dx:LayoutItemNestedControlContainer>
            </LayoutItemNestedControlCollection>
        </dx:LayoutItem>
        <!-- ... -->
    </Items>
</dx:LayoutGroup>

To find a layout item by its name, call the control's FindItemOrGroupByName method and pass the item's Name property value as a parameter.

LayoutItemBase baseItem = layout.FindItemOrGroupByName(ASPxComboBox1.Value.ToString()) as LayoutItemBase;

To access a control placed in a layout item, use the LayoutItem.Controls property. The code sample below traverses through the collection of nested controls and assigns new values to the controls.

var layoutItem = (baseItem as LayoutItem);
foreach (var control in layoutItem.Controls) {
    ASPxEdit editor = control as ASPxEdit;
    if (editor != null)
        editor.Value = DateTime.Now;
}

Files to Review

Documentation