Auto-generate hierarchy - when to set datakeynames for detail tables

2 posts, 0 answers
  1. Kris
    Kris avatar
    47 posts
    Member since:
    Feb 2008

    Posted 23 Feb 2012 Link to this post

    I am following this example to implement a grid. 

    My radgrid markup is below:

    <telerik:RadGrid ID="RadGrid1" runat="server" Height="412px" Width="818px" AutoGenerateColumns="true"
        AllowSorting="true" GroupingSettings-CaseSensitive="false" ClientSettings-Scrolling-AllowScroll="true"
        AutoGenerateHierarchy="true" PageSize="20" Skin="WebBlue" PagerStyle-AlwaysVisible="true"
        ClientSettings-ClientEvents-OnRowDblClick="RowDblClick" ClientSettings-Resizing-AllowColumnResize="true"
        ClientSettings-Scrolling-UseStaticHeaders="false" ClientSettings-Selecting-AllowRowSelect="true"
        ClientSettings-ClientEvents-OnRowClick="RadGrid1_RowSelected" ClientSettings-Scrolling-SaveScrollPosition="true"
        AllowFilteringByColumn="true" AllowPaging="true" OnNeedDataSource="RadGrid1_NeedDataSource"
        OnDetailTableDataBind="RadGrid1_DetailTableDataBind" OnColumnCreated="RadGrid1_ColumnCreated"
        OnPreRender="RadGrid1_PreRender" OnItemDataBound="RadGrid1_ItemDataBound"
        OnItemCreated="RadGrid1_ItemCreated" ondatabound="RadGrid1_DataBound">
        <MasterTableView AllowMultiColumnSorting="True" ClientDataKeyNames="rvlPropertyID"
            DataKeyNames="rvlPropertyID" HierarchyLoadMode="Client" Name="Property" Width="100%">
        <HeaderStyle VerticalAlign="Top" Width="125px" />
        <PagerStyle AlwaysVisible="True" />

    I have a drop down that changes the child level of the grid, where it be Assessment or Access. The problem I am running in to is that I allow the user to double click on a row in the child level, and then I will grab the dataKeyValue and launch an editor. I've tried putting these lines in the PreRender event, but it did not work.

    switch (m_GridViewType)
        case "Access":
            RadGrid1.MasterTableView.DetailTables[0].Name = "Access";
            RadGrid1.MasterTableView.DetailTables[0].DataKeyNames = new string[] { "rvlPropertyID", "rvlPropertyAccessID" };
            RadGrid1.MasterTableView.DetailTables[0].ClientDataKeyNames = new string[] { "rvlPropertyID", "rvlPropertyAccessID" };
        case "Assessment":
            RadGrid1.MasterTableView.DetailTables[0].Name = "Assessment";
            RadGrid1.MasterTableView.DetailTables[0].DataKeyNames = new string[] { "rvlPropertyID", "rvlPropAssessmentID" };
            RadGrid1.MasterTableView.DetailTables[0].ClientDataKeyNames = new string[] { "rvlPropertyID", "rvlPropAssessmentID" };
        case "Status":
            RadGrid1.MasterTableView.DetailTables[0].Name = "Status";
            RadGrid1.MasterTableView.DetailTables[0].DataKeyNames = new string[] { "rvlPropertyID", "rvlPropertyStatusID" };
            RadGrid1.MasterTableView.DetailTables[0].ClientDataKeyNames = new string[] { "rvlPropertyID", "rvlPropertyStatusID" };
        case "Contact":
            RadGrid1.MasterTableView.DetailTables[0].Name = "Contact";
            RadGrid1.MasterTableView.DetailTables[0].DataKeyNames = new string[] { "rvlPropertyID", "cntContactID" };
            RadGrid1.MasterTableView.DetailTables[0].ClientDataKeyNames = new string[] { "rvlPropertyID", "cntContactID" };
        case "Call":
            RadGrid1.MasterTableView.DetailTables[0].Name = "Call";
            RadGrid1.MasterTableView.DetailTables[0].DataKeyNames = new string[] { "rvlPropertyID", "clnCallinLogID" };
            RadGrid1.MasterTableView.DetailTables[0].ClientDataKeyNames = new string[] { "rvlPropertyID", "clnCallinLogID" };

    But the javascript method never pulls the datakeyValue because it does not have the datakeynames

    function RowDblClick(sender, eventArgs) {
              var propid = eventArgs.getDataKeyValue("rvlPropertyID");
              switch (document.getElementById('<%=cmbGridViews.ClientID %>').value) {
                  case "Access":
                      var childID = eventArgs.getDataKeyValue("RvlPropertyAccessID");
                  case "Assessment":
                      var childID = eventArgs.getDataKeyValue("RvlPropAssessmentID");
                  case "Status":
                      var childID = eventArgs.getDataKeyValue("RvlPropertyStatusID");
                  case "Contact":
                      var childID = eventArgs.getDataKeyValue("CntContactID");
                  case "Call":
                      var childID = eventArgs.getDataKeyValue("ClnCallinLogID");
              var targetCell = eventArgs.get_domEvent().target;
              if (childID == undefined) {
                  if (targetCell.cellIndex == 1) // Property Name
                      window.radopen("Editors/PropertyEditor.aspx?propid=" + propid, "editWindow");
                  else if (targetCell.cellIndex == 7 && targetCell.innerHTML != "0") // photocounter and does not = 0
                      window.radopen(GetPhotoViewerURL() + "PhotoViewer.aspx?id=" + propid, "PhotoWindow");
              else { // is child row
                  if (targetCell.cellIndex == 0) // Assessment date
                      window.radopen("Editors/PropertyAssessmentEditor.aspx?id=" + rvlAssessmentID, "editWindow");
                  else if (targetCell.cellIndex == 11 && targetCell.innerHTML != "0")
                      window.radopen(GetPhotoViewerURL() + "PhotoViewer.aspx?id=" + rvlAssessmentID, "PhotoWindow");
  2. Tsvetoslav
    Tsvetoslav avatar
    1823 posts

    Posted 28 Feb 2012 Link to this post

    Hi Kris,

    Setting the data key names/client data key names with auto-generated hierarchy is not supported. You need to use the GetCellByColumnUniqueName(....) method of the grid's client-side table view object:

    All the best, Tsvetoslav
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Back to Top