Click here to Skip to main content
15,920,896 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
hi, i found this Google tree view code to generate a tree view. i modified it little bit to make it more simpler. here it is.

JavaScript
google.setOnLoadCallback(drawChart);
function drawChart() {
            var data = new google.visualization.DataTable();
            data.addColumn('string', 'Name');
            data.addColumn('string', 'Manager');
            

            data.addRows([['Mike',''], ['Jim', 'Mike'], ['Alice', 'Mike'],['Bob', 'Jim'],['Carol', 'Jim']]);

            var chart = new google.visualization.OrgChart(document.getElementById('chart_div'));
            chart.draw(data, { allowHtml: true });
        }


but to make it dynamic i have to provide data from db(from C# page). for that i did this.

C#
protected void Page_Load(object sender, EventArgs e)
        {
            // Define the name and type of the client scripts on the page.
            String csname1 = "PopupScript";
            Type cstype = this.GetType();

            // Get a ClientScriptManager reference from the Page class.
            ClientScriptManager cs = Page.ClientScript;

            // Check to see if the startup script is already registered.
            if (!cs.IsStartupScriptRegistered(cstype, csname1))
            {
                StringBuilder cstext1 = new StringBuilder();
                cstext1.Append("<script type=text/javascript>");
                
                cstext1.Append("function drawChart() {");
                cstext1.Append("var data = new google.visualization.DataTable();");
                cstext1.Append("data.addColumn('string', 'Name'); data.addColumn('string', 'Manager');");
                cstext1.Append("data.addRows([['Mike',''], ['Jim', 'Mike'], ['Alice', 'Mike'],['Bob', 'Jim'],['Carol', 'Jim']]);");
                cstext1.Append("var chart = new google.visualization.OrgChart(document.getElementById('chart_div'));");
                cstext1.Append("chart.draw(data, { allowHtml: true });");
                cstext1.Append("}");
                cstext1.Append("google.setOnLoadCallback(drawChart);");
                cstext1.Append("</script>");

                //cstext1.Append("<script type=text/javascript>");
                //cstext1.Append("alert('s');");
                //cstext1.Append("</script>");

                cs.RegisterStartupScript(cstype, csname1, cstext1.ToString());
            }
        }


but after loading the page is blank..no data is showing.. my intention is to change the 2d array with an own variable which will hold the array. I kept the array as it was.

kindly solve the issue.

thanks..
Posted
Comments
ZurdoDev 14-Jan-15 16:39pm    
I'd suggest debugging and making sure cstext1 does not have any syntax errors in it.
Arkadeep De 16-Jan-15 0:11am    
yes u wear right...a " was missing..thanks
ZurdoDev 16-Jan-15 7:23am    
Sure.

1 solution

As mentioned in the comments, check to make sure that cstext1 does not have any syntax errors in it. It's easy to have syntax errors when you build up a string this way.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900