View accounts like hierarchy / treeview

This question is not answered

I need to create a solution to display accounts like a hierarchy or in a tree view.  I was able to create a solution to display all of the accounts in the system this way by modifying something I found here (http://www.c-sharpcorner.com/UploadFile/desaijm/database_hierarchy_with_datarelation02192006170040PM/database_hierarchy_with_datarelation.aspx) to work with CRM, but I need a way to only show a single "branch" of the tree depending on what account the end user has selected.  They only want to see the related accounts when an account is selected and I'm not sure how to do it.  Any guidance?

All Replies
  • Great work Ryan!  I made one quick change.  Let me know if you know of a better way to work around this issue.

    So, with the way the ASP.Net TreeView works out of the box it opens the window using an href.  We set the target to new to open in a new window, however it doesn't hide the toolbar and set it to the right size.  I found a hack to get it to open the window through javascript. 

    Set onclick of the treeview to trigger a javascript function: 

     <asp:TreeView   onclick="BLOCKED SCRIPTpostBackByObject()" ID="TreeView1" runat="server" ImageSet="Arrows"> 

     

    Add a function to intercept the opening of a link and do it through BLOCKED SCRIPT

    function postBackByObject()
    {
    if(window.event.srcElement.href != null
    && window.event.srcElement.href != ""
    && window.event.srcElement.href.substr(0,4).toLocaleLowerCase() == "http"
    && window.event.srcElement.nameProp.substr(0,11).toLocaleLowerCase() != "webresource")
    {
    window.open(window.event.srcElement.href,'popup','toolbar=no,location=no,directories=no,status=yes,scrollbars=yes,menubar=no,resizable=yes,width=1000,height=560');
    }

    // clicks that are expanding the treeview come in with webresource - let them occur
    if(window.event.srcElement.href != null
    && window.event.srcElement.href != ""
    && window.event.srcElement.href.substr(0,4).toLocaleLowerCase() == "http"
    && window.event.srcElement.nameProp.substr(0,11).toLocaleLowerCase() != "webresource")
    {
        event.returnValue = false;
        return false;

    }


     

     Full Code Page:

    <%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title>Account Hierarchy</title>
        <style type="text/css" media="screen">

            a,a:link,a:visited,a:active
            {
                  font-family: Tahoma, Verdana, Arial;
                  color: #15428b;
                  text-decoration: none;
                  font-size: small;
            }

            a:hover
            {
                  color:#0000ff;
                  text-decoration:underline;
            }

            body
            {
            background-color: #EAF3FF; 
            }

        </style>
        <script language="javascript" type="text/javascript">


    function postBackByObject()
    {

    if(window.event.srcElement.href != null
    && window.event.srcElement.href != ""
    // click that don't have a URL show up with javascript
    && window.event.srcElement.href.substr(0,10).toLocaleLowerCase() != "javascript"
    // clicks that are expanding the treeview come in with webresource
    && window.event.srcElement.nameProp.substr(0,11).toLocaleLowerCase() != "webresource")
    {
    window.open(window.event.srcElement.href,'popup','toolbar=no,location=no,directories=no,status=yes,scrollbars=yes,menubar=no,resizable=yes,width=1000,height=560');
    }

    // clicks that are expanding the treeview come in with webresource - let them occur
    if(window.event.srcElement.nameProp.substr(0,11).toLocaleLowerCase() != "webresource")
    {
        event.returnValue = false;
        return false;

    }


        </script>
       

    </head>
     <body marginheight="0" topmargin="0" vspace="0" marginwidth="0" leftmargin="0" hspace="0" style="margin:0px; padding:0px; border:none;" MS_POSITIONING="GridLayout">
        <form id="form1" runat="server">
        <div>
        <asp:xml id="Xml1" runat="server"></asp:xml>
                <asp:TreeView   onclick="BLOCKED SCRIPTpostBackByObject()" ID="TreeView1" runat="server" ImageSet="Arrows">

                <ParentNodeStyle Font-Bold="False" />

                <HoverNodeStyle Font-Underline="True" ForeColor="#5555DD" />

                <SelectedNodeStyle Font-Underline="True" ForeColor="#5555DD"

                    HorizontalPadding="0px" VerticalPadding="0px" />

                <NodeStyle Font-Names="Tahoma" Font-Size="10pt" ForeColor="Black"

                    HorizontalPadding="5px" NodeSpacing="0px" VerticalPadding="0px" />

            </asp:TreeView>
        </div>
        </form>
    </body>
    </html>


     

     

  • Thanks for sharing the sample.

    Unfortunately this will not work when deployment is on multiple server and  CRM and SQL is on separated machines. (Double Hops)

    Maybe use CRM WebServices to retrieve information and not directly to SQL.

  • Hi Shai, Can you elaborate on your error?  Are you having problems connecting to the database using windows authentication.  You will want to double check that you putting the code in a folder under the /ISV/... directory.  If may also having problems while running it using .Net's built-in web server (casinni), since it uses may run under a different account than the user (ASPNET, ect).  Lastly, make sure you have the IFRAME set up to allow for cross-page scripting.  Since the ASP.Net TreeView uses JavaScript behind the screens, it won't work unless you allow for it. I would stay away from using the CRM web service, because of performance concerns with a larger hierarchy. Send me over the error you are getting.  Hopefully I can help out.  -Andrew
    http://blogs.inetium.com/blogs/azimmer

     

  • To clarify: From your ASPX page (IFRAME) are you calling a web service on another machine to handle data access?  If so, the credentials will not go along with it.  In this double-hop scenario you have a couple options.  One, you can set up kerberos to propogate the credentials.  From what I hear it is a lot of work. 

    Or two, you can set up your website of the web service to run as a user who has access to the CRM database's security group.  In this case you will probably want to have this run as a server account that no one else uses.  This would require you to burn a CRM license key.

    Andrew Zimmer


    http://blogs.inetium.com/blogs/azimmer/
  • Normal 0 false false false EN-US X-NONE HE MicrosoftInternetExplorer4 /* Style Definitions */ table.MsoNormalTable {mso-style-name:"Table Normal"; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-priority:99; mso-style-qformat:yes; mso-style-parent:""; mso-padding-alt:0in 5.4pt 0in 5.4pt; mso-para-margin-top:0in; mso-para-margin-right:0in; mso-para-margin-bottom:10.0pt; mso-para-margin-left:0in; line-height:115%; mso-pagination:widow-orphan; font-size:11.0pt; font-family:"Calibri","sans-serif"; mso-ascii-font-family:Calibri; mso-ascii-theme-font:minor-latin; mso-fareast-font-family:"Times New Roman"; mso-fareast-theme-font:minor-fareast; mso-hansi-font-family:Calibri; mso-hansi-theme-font:minor-latin;}

    The error I was getting is: error "NT AUTHORITY/ANONYMOUS LOGON".

    See: http://blog.sonomapartners.com/2007/04/kerberos_and_de.html  for nice description.

    You are calling CRM Database Directly .The Iframe is running under Windows Integrated security, but this is good when you running on the server or both SQL & CRM are on the same server. But if you call it from client desktop, then from client machine to CRM Server is the "1st Hop”, from the Iframe (CRM server) to SQL server is the "2nd Hop".

    I used the tip from : http://jianwang.blogspot.com/2008/09/filteredview-and-crmimpersonator.html  to solve the problem.

    I'll refine it and make it generic and sent it to you, so you can publish it. (In your blog too)