aspnet-3922-components-grid-view-concepts-templates-accessing-controls-contained-within-templates.md
ASPxGridView has multiple methods that allow you to access controls contained within templates. These methods are listed in the following topic: Member Table: Templates.
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.
<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>
protected void ASPxGridView1_HtmlRowPrepared(object sender, ASPxGridViewTableRowEventArgs e) {
ASPxButtonEdit btnEdit = ASPxGridView1.FindRowCellTemplateControl(e.VisibleIndex,
ASPxGridView1.Columns["Name"] as GridViewDataColumn, "ASPxButtonEdit1") as ASPxButtonEdit;
if (Convert.ToInt32(ASPxGridView1.GetRowValues(e.VisibleIndex, "Age")) > 30)
btnEdit.Enabled = false;
}
Protected Sub ASPxGridView1_HtmlRowPrepared(ByVal sender As Object, ByVal e As ASPxGridViewTableRowEventArgs)
Dim btnEdit As ASPxButtonEdit = TryCast(ASPxGridView1.FindRowCellTemplateControl(e.VisibleIndex, TryCast(ASPxGridView1.Columns("Name"), GridViewDataColumn), "ASPxButtonEdit1"), ASPxButtonEdit)
If Convert.ToInt32(ASPxGridView1.GetRowValues(e.VisibleIndex, "Age")) > 30 Then
btnEdit.Enabled = False
End If
End Sub
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.
<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>
protected void ASPxGridView1_HtmlRowCreated(object sender, ASPxGridViewTableRowEventArgs e) {
if (e.RowType != GridViewRowType.InlineEdit) return;
ASPxTextBox txtBox = ASPxGridView1.FindEditRowCellTemplateControl(ASPxGridView1.Columns["Name"] as GridViewDataColumn, "ASPxTextBox1") as ASPxTextBox;
if (txtBox == null) return;
if (Convert.ToInt32(ASPxGridView1.GetRowValues(e.VisibleIndex, "Age")) > 30)
txtBox.Enabled = false;
}
Protected Sub ASPxGridView1_HtmlRowCreated(ByVal sender As Object, ByVal e As ASPxGridViewTableRowEventArgs)
If e.RowType <> GridViewRowType.InlineEdit Then
Return
End If
Dim txtBox As ASPxTextBox = TryCast(ASPxGridView1.FindEditRowCellTemplateControl(TryCast(ASPxGridView1.Columns("Name"), GridViewDataColumn), "ASPxTextBox1"), ASPxTextBox)
If txtBox Is Nothing Then
Return
End If
If Convert.ToInt32(ASPxGridView1.GetRowValues(e.VisibleIndex, "Age")) > 30 Then
txtBox.Enabled = False
End If
End Sub