Skip to main content
Tab

GridViewBaseRowTemplateContainer.KeyValue Property

Gets an object that uniquely identifies the row that contains the template container.

Namespace: DevExpress.Web

Assembly: DevExpress.Web.v24.1.dll

NuGet Package: DevExpress.Web

Declaration

public virtual object KeyValue { get; }

Property Value

Type Description
Object

An object that uniquely identifies the row that contains the template container.

Example

Sometimes it is necessary to show hierarchical data inside a detail ASPxGridView row. ASPxTreeList can show hierarchical data, but it does not have the built-in capability to get a corresponding master row key value.

To get a grid master row key value, it is necessary to move up through a hierarchy of controls to find the GridViewBaseRowTemplateContainer that has the KeyValue property. This is a universal solution and it can be applied to any ASP.NET control held in a grid template.

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using DevExpress.Web.ASPxGridView;
using DevExpress.Web.ASPxTreeList;

public partial class _Default : System.Web.UI.Page 
{
    protected void Page_Load(object sender, EventArgs e) {

    }

    protected object GetMasterRowKeyValue(ASPxTreeList treeList) {
        GridViewBaseRowTemplateContainer container = null;
        Control control = treeList;
        while(control.Parent != null) {
            container = control.Parent as GridViewBaseRowTemplateContainer;
            if(container != null) break;
            control = control.Parent;
        }
        return container.KeyValue;
    }

    protected void ASPxTreeList1_Init(object sender, EventArgs e) {
        ASPxTreeList treeList = sender as ASPxTreeList;
        object keyValue = GetMasterRowKeyValue(treeList);
        treeList.RootValue = keyValue;
    }
}

The following code snippets (auto-collected from DevExpress Examples) contain references to the KeyValue property.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

See Also