Skip to main content
A newer version of this page is available. .

Accessing Controls Contained within Templates

  • 2 minutes to read

ASPxGridView provides multiple methods that allow you to access controls contained within templates. These methods are listed in the Member Table: Templates help topic.

Example 1: Data Item Template

In this example, the ASPxGridView.FindRowCellTemplateControl method is used to access ASPxButtonEdit template controls contained within column cells. If the processed customer is older than 30, the ASPxButtonEdit control is disabled.

cdObtainTemplateControls_ex1

<dx:ASPxGridView ID="ASPxGridView1" runat="server" OnHtmlRowPrepared="ASPxGridView1_HtmlRowPrepared" DataSourceID="SqlDataSource1" ...>
    <Columns>
        <dx:GridViewDataTextColumn FieldName="Oid" VisibleIndex="0">
        </dx:GridViewDataTextColumn>
        <dx:GridViewDataTextColumn FieldName="Name" VisibleIndex="1">
        </dx:GridViewDataTextColumn>
        <dx:GridViewDataTextColumn FieldName="Age" VisibleIndex="2">
        </dx:GridViewDataTextColumn>
    </Columns>
    ...
</dx:ASPxGridView>

Example 2: Edit Item Template

In this example, the ASPxGridView.FindEditRowCellTemplateControl method is used to access text box template controls contained within the Name column’s edit cells. If the processed customer is older than 30, the text box is disabled.

cdObtainTemplateCtrls_ex2

<dx:ASPxGridView ID="ASPxGridView1" runat="server" OnHtmlRowCreated="ASPxGridView1_HtmlRowCreated" DataSourceID="SqlDataSource1" ...>
    <Columns>
        <dx:GridViewDataTextColumn FieldName="Oid" VisibleIndex="0">
        </dx:GridViewDataTextColumn>
        <dx:GridViewDataTextColumn FieldName="Name" VisibleIndex="1">
        </dx:GridViewDataTextColumn>
        <dx:GridViewDataTextColumn FieldName="Age" VisibleIndex="2">
        </dx:GridViewDataTextColumn>
    </Columns>
    ...
</dx:ASPxGridView>