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.

    http://demos.telerik.com/aspnet-ajax/grid/examples/hierarchy/autogeneratedhierarchy/defaultcs.aspx 

    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%">
        </MasterTableView>
        <HeaderStyle VerticalAlign="Top" Width="125px" />
        <PagerStyle AlwaysVisible="True" />
    </telerik:RadGrid>


    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" };
            break;
        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" };
            break;
        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" };
            break;
        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" };
            break;
        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" };
            break;
    }


    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");
                      break;
                  case "Assessment":
                      var childID = eventArgs.getDataKeyValue("RvlPropAssessmentID");
                      break;
                  case "Status":
                      var childID = eventArgs.getDataKeyValue("RvlPropertyStatusID");
                      break;
                  case "Contact":
                      var childID = eventArgs.getDataKeyValue("CntContactID");
                      break;
                  case "Call":
                      var childID = eventArgs.getDataKeyValue("ClnCallinLogID");
                      break;
                  default:
                      break;
              }
     
              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
    Admin
    Tsvetoslav avatar
    1823 posts
    Member since:
    Sep 2012

    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:
    http://www.telerik.com/help/aspnet-ajax/grid-gridtableview-getcellbycolumnuniquename.html


    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