Back to Devexpress

ASPxTreeList.FindDataCellTemplateControl(String, TreeListDataColumn, String) Method

aspnet-devexpress-dot-web-dot-aspxtreelist-dot-aspxtreelist-dot-finddatacelltemplatecontrol-x28-system-dot-string-devexpress-dot-web-dot-aspxtreelist-dot-treelistdatacolumn-system-dot-string-x29.md

latest4.9 KB
Original Source

ASPxTreeList.FindDataCellTemplateControl(String, TreeListDataColumn, String) Method

Searches for the server control contained within the specified data cell’s template.

Namespace : DevExpress.Web.ASPxTreeList

Assembly : DevExpress.Web.ASPxTreeList.v25.2.dll

NuGet Package : DevExpress.Web

Declaration

csharp
public Control FindDataCellTemplateControl(
    string nodeKey,
    TreeListDataColumn column,
    string id
)
vb
Public Function FindDataCellTemplateControl(
    nodeKey As String,
    column As TreeListDataColumn,
    id As String
) As Control

Parameters

NameTypeDescription
nodeKeyString

A String value that identifies the node.

| | column | TreeListDataColumn |

A TreeListDataColumn object that represents the data column where the requested cell resides. If null ( Nothing in Visual Basic), the search is performed within all cells in the specified node.

| | id | String |

A String value that identifies the control within the specified cell.

|

Returns

TypeDescription
Control

A Control object that represents the control contained within the specified data cell’s template.

|

Remarks

To learn more, see Templates.

Example

In this example, the ASPxTreeList.HtmlRowPrepared event is handled to display appropriate images within data cells. The ASPxTreeList.FindDataCellTemplateControl method is used to access ASPxImage and ASPxLabel template controls contained within data cells.

The image below shows the result:

csharp
protected void ASPxTreeList1_HtmlRowPrepared(object sender,
DevExpress.Web.ASPxTreeList.TreeListHtmlRowEventArgs e) {
    if(e.RowKind != DevExpress.Web.ASPxTreeList.TreeListRowKind.Data) return;
    ASPxImage img = ASPxTreeList1.FindDataCellTemplateControl(e.NodeKey,
      ASPxTreeList1.Columns["Product"] as TreeListDataColumn, "ASPxImage1") as ASPxImage;
    ASPxLabel lb = ASPxTreeList1.FindDataCellTemplateControl(e.NodeKey,
      ASPxTreeList1.Columns["Product"] as TreeListDataColumn, "ASPxLabel1") as ASPxLabel;
    if (ASPxTreeList1.FindNodeByKeyValue(e.NodeKey).HasChildren) {
        img.ImageUrl = @"~\i\product-group.png";
        lb.Font.Size = 12;
        lb.Font.Bold = true;
    }
    else
        img.ImageUrl = @"~\i\product.png";
}
aspx
<dx:ASPxTreeList ID="ASPxTreeList1" runat="server" AutoGenerateColumns="False"
    DataSourceID="AccessDataSource1" KeyFieldName="ID" ParentFieldName="ParentID"
    Width="200px" OnHtmlRowPrepared="ASPxTreeList1_HtmlRowPrepared">
    <Columns>
        <dx:TreeListDataColumn Caption="Products" FieldName="Product" VisibleIndex="0">
            <DataCellTemplate>
            <table cellspacing="0">
                <tr>
                    <td>
                        <dx:ASPxImage ID="ASPxImage1" runat="server">
                        </dx:ASPxImage>
                    </td>
                    <td style="vertical-align:middle">
                        <dx:ASPxLabel ID="ASPxLabel1" runat="server"
                         Text='<%# Eval("Product") %>'>
                        </dx:ASPxLabel>
                    </td>
                </tr>
            </table>
            </DataCellTemplate>
        </dx:TreeListDataColumn>
    </Columns>
</dx:ASPxTreeList>

See Also

Tree List

ASPxTreeList Class

ASPxTreeList Members

DevExpress.Web.ASPxTreeList Namespace