Skip to main content

Accessing Controls Contained within Templates

  • 2 minutes to read

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

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>