protected override void Render( HtmlTextWriter writer )
		{
			if( Request.QueryString["t"] == "ajaxAdd" )
			{
				string addNodeText = HttpUtility.UrlDecode( Request.QueryString["addNodeText"] );
				int parentNodeValue = int.Parse( HttpUtility.UrlDecode( Request.QueryString["parentNodeValue"] ) );

				string maxSql = "select max( productId ) from products";
				int max = (int)OleDbHelper.ExecuteScalar( base.NorthWindConnectionString, CommandType.Text, maxSql );
				int newId = max + 1;

				string sql = string.Format( @"INSERT INTO products( productid, Discontinued, productname, parentid ) values( {0} ,0, '{1}', {2})"
					, max + 1, addNodeText.Replace( "'", "''" ), parentNodeValue );

				int i = OleDbHelper.ExecuteNonQuery( base.NorthWindConnectionString, CommandType.Text, sql );

				ASTreeViewNode root = new ASTreeViewNode( "root" );

				ASTreeViewLinkNode node = new ASTreeViewLinkNode( addNodeText, newId.ToString() );
				node.NavigateUrl = "#";
				node.AdditionalAttributes.Add( new KeyValuePair<string, string>( "onclick", "return false;" ) );

				root.AppendChild( node );

				HtmlGenericControl ulRoot = new HtmlGenericControl( "ul" );
				astvMyTree.TreeViewHelper.ConvertTree( ulRoot, root, false );
				foreach( Control c in ulRoot.Controls )
					c.RenderControl( writer );

				/*
				foreach( DataRow dr in dt.Rows )
				{
					string productName = dr["ProductName"].ToString();
					string productId = dr["ProductID"].ToString();
					string parentId = dr["ParentID"].ToString();
					int childNodesCount = 0;
					if( !string.IsNullOrEmpty( dr["ChildNodesCount"].ToString() ) )
						childNodesCount = int.Parse( dr["ChildNodesCount"].ToString() );

					ASTreeViewLinkNode node = new ASTreeViewLinkNode( productName, productId );
					node.VirtualNodesCount = childNodesCount;
					node.VirtualParentKey = productId;
					node.IsVirtualNode = childNodesCount > 0;
					node.NavigateUrl = "#";
					node.AdditionalAttributes.Add( new KeyValuePair<string, string>( "onclick", "return false;" ) );

					root.AppendChild( node );
				}



				HtmlGenericControl ulRoot = new HtmlGenericControl( "ul" );
				astvMyTree.TreeViewHelper.ConvertTree( ulRoot, root, false );
				foreach( Control c in ulRoot.Controls )
					c.RenderControl( writer );*/
			}
			else
				base.Render( writer );

		}
Exemplo n.º 2
0
        protected override void Render(HtmlTextWriter writer)
        {
            if (Request.QueryString["t"] == "ajaxAdd")
            {
                string addNodeText     = HttpUtility.UrlDecode(Request.QueryString["addNodeText"]);
                int    parentNodeValue = int.Parse(HttpUtility.UrlDecode(Request.QueryString["parentNodeValue"]));

                if (addNodeText.ToLower().IndexOf("a") >= 0)
                {
                    ASTreeViewNode root = new ASTreeViewNode("root");

                    ASTreeViewLinkNode node = new ASTreeViewLinkNode("[Server Said]:You cannot add node with nodetext containing letter 'a'", "failed");
                    node.AdditionalAttributes.Add(new KeyValuePair <string, string>("addfailed", "true"));

                    root.AppendChild(node);

                    HtmlGenericControl ulRoot = new HtmlGenericControl("ul");
                    astvMyTree.TreeViewHelper.ConvertTree(ulRoot, root, false);
                    foreach (Control c in ulRoot.Controls)
                    {
                        c.RenderControl(writer);
                    }
                }
                else
                {
                    string maxSql = "select max( productId ) from products";
                    int    max    = (int)OleDbHelper.ExecuteScalar(base.NorthWindConnectionString, CommandType.Text, maxSql);
                    int    newId  = max + 1;

                    string sql = string.Format(@"INSERT INTO products( productid, Discontinued, productname, parentid ) values( {0} ,0, '{1}', {2})"
                                               , max + 1, addNodeText.Replace("'", "''"), parentNodeValue);

                    int i = OleDbHelper.ExecuteNonQuery(base.NorthWindConnectionString, CommandType.Text, sql);

                    ASTreeViewNode root = new ASTreeViewNode("root");

                    ASTreeViewLinkNode node = new ASTreeViewLinkNode(addNodeText, newId.ToString());
                    node.NavigateUrl = "#";
                    node.AdditionalAttributes.Add(new KeyValuePair <string, string>("onclick", "return false;"));

                    root.AppendChild(node);

                    HtmlGenericControl ulRoot = new HtmlGenericControl("ul");
                    astvMyTree.TreeViewHelper.ConvertTree(ulRoot, root, false);
                    foreach (Control c in ulRoot.Controls)
                    {
                        c.RenderControl(writer);
                    }
                }
            }
            else
            {
                base.Render(writer);
            }
        }
		protected override void Render( HtmlTextWriter writer )
		{
			if( Request.QueryString["t"] == "ajaxAdd" )
			{
				string addNodeText = HttpUtility.UrlDecode( Request.QueryString["addNodeText"] );
				int parentNodeValue = int.Parse( HttpUtility.UrlDecode( Request.QueryString["parentNodeValue"] ) );

				if( addNodeText.ToLower().IndexOf( "a" ) >= 0 )
				{
					ASTreeViewNode root = new ASTreeViewNode( "root" );

					ASTreeViewLinkNode node = new ASTreeViewLinkNode( "[Server Said]:You cannot add node with nodetext containing letter 'a'", "failed" );
					node.AdditionalAttributes.Add( new KeyValuePair<string, string>( "addfailed", "true" ) );

					root.AppendChild( node );

					HtmlGenericControl ulRoot = new HtmlGenericControl( "ul" );
					astvMyTree.TreeViewHelper.ConvertTree( ulRoot, root, false );
					foreach( Control c in ulRoot.Controls )
						c.RenderControl( writer );
				}
				else
				{
					string maxSql = "select max( productId ) from products";
					int max = (int)OleDbHelper.ExecuteScalar( base.NorthWindConnectionString, CommandType.Text, maxSql );
					int newId = max + 1;

					string sql = string.Format( @"INSERT INTO products( productid, Discontinued, productname, parentid ) values( {0} ,0, '{1}', {2})"
						, max + 1, addNodeText.Replace( "'", "''" ), parentNodeValue );

					int i = OleDbHelper.ExecuteNonQuery( base.NorthWindConnectionString, CommandType.Text, sql );

					ASTreeViewNode root = new ASTreeViewNode( "root" );

					ASTreeViewLinkNode node = new ASTreeViewLinkNode( addNodeText, newId.ToString() );
					node.NavigateUrl = "#";
					node.AdditionalAttributes.Add( new KeyValuePair<string, string>( "onclick", "return false;" ) );

					root.AppendChild( node );

					HtmlGenericControl ulRoot = new HtmlGenericControl( "ul" );
					astvMyTree.TreeViewHelper.ConvertTree( ulRoot, root, false );
					foreach( Control c in ulRoot.Controls )
						c.RenderControl( writer );
				}
			}
			else
				base.Render( writer );

		}
        private void GenerateTree()
        {
            ASTreeViewLinkNode n = new ASTreeViewLinkNode("Picasa", "Picasa", "http://picasaweb.google.com", "frm", "Goto Picasa", "~/Images/demoIcons/picasa.gif");

            n.NodeText              = "The node cannot have children.";
            n.EnableChildren        = false;
            n.EnableEditContextMenu = false;

            //n.AdditionalAttributes.Add( new KeyValuePair<string, string>( "onclick", "alert(1);return false;" ) );
            //n.AdditionalAttributes.Add( new KeyValuePair<string, string>( "disableChildren1", "true" ) );

            this.astvMyTree.RootNode
            //.AppendChild( new ASTreeViewLinkNode( "Accor", "Accor", "http://www.accor.com", "frm", "Goto Accor", "~/Images/demoIcons/accor.gif" )
            //                    .AppendChild( new ASTreeViewLinkNode( "Accor Services", "Accor Services", "http://www.accorservices.com", "frm", "Goto Accor Services", "~/Images/demoIcons/accorservices.gif" ) )
            //                    .AppendChild( new ASTreeViewLinkNode( "Accor Hospitality", "Accor Hospitality", "http://www.accorhotels.com", "frm", "Goto Accor Hospitality", "~/Images/demoIcons/accorhospitality.gif" ) )
            //)
            .AppendChild(new ASTreeViewLinkNode("GM", "GM", "http://www.gm.com", "frm", "Goto GM.com", "~/Images/demoIcons/gm.gif")
                         .AppendChild(new ASTreeViewLinkNode("Hummer", "Hummer", "http://www.hummer.com", "frm", "Goto Hummer.com", "~/Images/demoIcons/hummer.gif"))
                         .AppendChild(new ASTreeViewLinkNode("Cadillac", "Cadillac", "http://www.cadillac.com", "frm", "Goto Cadillac.com", "~/Images/demoIcons/cadillac.gif"))
                         .AppendChild(new ASTreeViewLinkNode("SAAB", "SAAB", "http://www.saab.com", "frm", "Goto SAAB.com", "~/Images/demoIcons/saab.gif"))
                         )
            .AppendChild(new ASTreeViewLinkNode("Google", "Google Site", "http://www.google.com", "frm", "Goto Google", "~/Images/demoIcons/google.gif")
                         .AppendChild(new ASTreeViewLinkNode("Picasa", "Picasa", "http://picasaweb.google.com", "frm", "Goto Picasa", "~/Images/demoIcons/picasa.gif"))
                         )
            .AppendChild(new ASTreeViewLinkNode("Microsoft", "Microsoft", "http://www.microsoft.com", "frm", "Goto Microsoft", "~/Images/demoIcons/microsoft.gif")
                         .AppendChild(new ASTreeViewLinkNode("MSDN", "MSDN", "http://www.msdn.com", "frm", "Goto MSDN", "~/Images/demoIcons/msdn.gif"))
                         )
            .AppendChild(new ASTreeViewLinkNode("Amazon", "Amazon", "http://www.amazon.com", "frm", "Goto Amazon", "~/Images/demoIcons/amazon.gif").AppendChild(n))
            .AppendChild(new ASTreeViewLinkNode("<font style='color:blue;font-weight:bold;font-style:italic;' isTreeNodeChild='true'>ASTreeView</font>", "Best Free TreeView Control for ASP.Net", "http://www.astreeview.com", "frm", "Html as TreeNode Text", "~/Images/demoIcons/ast.gif")
                         );



            /*
             * string path = System.AppDomain.CurrentDomain.BaseDirectory;
             * string connStr = string.Format( "Provider=Microsoft.Jet.OLEDB.4.0;Data source={0}db\\NorthWind.mdb", path );
             *
             * DataSet ds = OleDbHelper.ExecuteDataset( connStr, CommandType.Text, "select * from [Products]" );
             *
             * ASTreeViewDataTableColumnDescriptor descripter = new ASTreeViewDataTableColumnDescriptor( "ProductName"
             *      , "ProductID"
             *      , "ParentID" );
             * //descripter.AddSingleQuotationOnQuery = false;
             * this.astvMyTree.DataTableColumnDescriptor = descripter;
             * this.astvMyTree.DataSource = ds.Tables[0];
             * this.astvMyTree.DataBind();
             */
        }
Exemplo n.º 5
0
        public static void GenerarTreeTipoProductos(ASTreeView astvMyTree, bool Buscador)
        {
            ASTreeViewLinkNode n100 = new ASTreeViewLinkNode("Marcos", "100", "", "frm", "madera maciza", "");
            n100.EnableCheckbox = Buscador;
            n100.EnableChildren = false;
            n100.EnableEditContextMenu = false;

            ASTreeViewLinkNode n400 = new ASTreeViewLinkNode("Mesas", "400", "", "frm", "", "");
            n400.EnableCheckbox = Buscador;
            n400.EnableChildren = false;
            n400.EnableEditContextMenu = false;

            ASTreeViewLinkNode n500 = new ASTreeViewLinkNode("Sillas y Bancos", "500", "", "frm", "", "");
            n500.EnableCheckbox = Buscador;
            n500.EnableChildren = false;
            n500.EnableEditContextMenu = false;

            ASTreeViewLinkNode n600 = new ASTreeViewLinkNode("Decoración", "600", "", "frm", "objetos decorativos", "");
            n600.EnableCheckbox = Buscador;
            n600.EnableChildren = false;
            n600.EnableEditContextMenu = false;

            astvMyTree.RootNode
                .AppendChild((n100)
                    .AppendChild(new ASTreeViewLinkNode("Madera Pinotea", "101", "", "frm", "madera maciza", ""))
                    .AppendChild(new ASTreeViewLinkNode("Madera Cedro", "102", "", "frm", "", ""))
                    .AppendChild(new ASTreeViewLinkNode("Vintage", "103", "", "frm", "madera maciza", ""))
                )
                .AppendChild(new ASTreeViewLinkNode("Espejos", "200", "", "frm", "", ""))
                .AppendChild(new ASTreeViewLinkNode("Carteles", "300", "", "frm", "", ""))
                .AppendChild((n400)
                    .AppendChild(new ASTreeViewLinkNode("Mesas Ratonas", "401", "", "frm", "Mesas Ratonas", ""))
                )
                .AppendChild((n500)
                    .AppendChild(new ASTreeViewLinkNode("Bancos Rústicos", "501", "", "frm", "En madera reciclada", ""))
                    .AppendChild(new ASTreeViewLinkNode("Bancos Modernos", "502", "", "frm", "En madera reciclada", ""))
                )
                .AppendChild((n600)
                    .AppendChild(new ASTreeViewLinkNode("Peces", "601", "", "frm", "madera y metal", ""))
                    .AppendChild(new ASTreeViewLinkNode("Barcos", "602", "", "frm", "madera y metal", ""))
                    .AppendChild(new ASTreeViewLinkNode("Caras", "603", "", "frm", "madera y metal", ""))
                    .AppendChild(new ASTreeViewLinkNode("Cuadros", "604", "", "frm", "madera y metal", ""))
                    .AppendChild(new ASTreeViewLinkNode("Objetos Varios", "650", "", "frm", "madera y metal", ""))
                );
        }
        private void GenerateTree2()
        {
            string para = "= 1";

            string sql = @"SELECT p1.[ProductID] as ProductID, p1.[ProductName] as ProductName, p3.childNodesCount as ChildNodesCount, p1.[ParentID] as ParentID
FROM [Products] p1
INNER JOIN 
(
	SELECT COUNT(*) AS childNodesCount , p2.[ParentID] AS pId 
	FROM [Products] p2
	GROUP BY p2.[ParentID]
) p3
ON p1.[ProductID] = p3.pId
WHERE p1.[ParentID] " + para;

            DataTable dt = OleDbHelper.ExecuteDataset(base.NorthWindConnectionString, CommandType.Text, sql).Tables[0];

            ASTreeViewNode root = this.astvMyTree2.RootNode;

            foreach (DataRow dr in dt.Rows)
            {
                string productName     = dr["ProductName"].ToString();
                string productId       = dr["ProductID"].ToString();
                string parentId        = dr["ParentID"].ToString();
                int    childNodesCount = int.Parse(dr["ChildNodesCount"].ToString());

                ASTreeViewLinkNode node = new ASTreeViewLinkNode(productName, productId);
                node.VirtualNodesCount = childNodesCount;
                node.VirtualParentKey  = productId;
                node.IsVirtualNode     = childNodesCount > 0;
                node.NavigateUrl       = "#";
                //List<KeyValuePair<string, string>> attrs = new List<KeyValuePair<string, string>>();
                node.AdditionalAttributes.Add(new KeyValuePair <string, string>("onclick", "return false;"));
                //node.AdditionalAttributes = attrs;

                root.AppendChild(node);
            }
        }
Exemplo n.º 7
0
        private void GenerateTree2()
        {
            string para = "= 1";

            string sql = @"SELECT p1.[ProductID] as ProductID, p1.[ProductName] as ProductName, p3.childNodesCount as ChildNodesCount, p1.[ParentID] as ParentID
            FROM [Products] p1
            INNER JOIN
            (
            SELECT COUNT(*) AS childNodesCount , p2.[ParentID] AS pId
            FROM [Products] p2
            GROUP BY p2.[ParentID]
            ) p3
            ON p1.[ProductID] = p3.pId
            WHERE p1.[ParentID] " + para;

            DataTable dt = OleDbHelper.ExecuteDataset( base.NorthWindConnectionString, CommandType.Text, sql ).Tables[0];

            ASTreeViewNode root = this.astvMyTree2.RootNode;

            foreach( DataRow dr in dt.Rows )
            {
                string productName = dr["ProductName"].ToString();
                string productId = dr["ProductID"].ToString();
                string parentId = dr["ParentID"].ToString();
                int childNodesCount = int.Parse( dr["ChildNodesCount"].ToString() );

                ASTreeViewLinkNode node = new ASTreeViewLinkNode( productName, productId );
                node.VirtualNodesCount = childNodesCount;
                node.VirtualParentKey = productId;
                node.IsVirtualNode = childNodesCount > 0;
                node.NavigateUrl = "#";
                //List<KeyValuePair<string, string>> attrs = new List<KeyValuePair<string, string>>();
                node.AdditionalAttributes.Add( new KeyValuePair<string, string>( "onclick", "return false;" ) );
                //node.AdditionalAttributes = attrs;

                root.AppendChild( node );
            }
        }
Exemplo n.º 8
0
        protected override void Render( HtmlTextWriter writer )
        {
            if( Request.QueryString["t1"] == "ajaxLoad" )
            {
                string virtualParentKey = Request.QueryString["virtualParentKey"];

                string para = string.Empty;// "= 1";
                if( virtualParentKey == null )
                    para = " is NULL";
                else
                    para = "=" + virtualParentKey;

                string sql = @"SELECT p1.[ProductID] as ProductID, p1.[ProductName] as ProductName, p1.[ParentID] as ParentID, p3.childNodesCount as ChildNodesCount
            FROM [Products] p1
            LEFT OUTER JOIN
            (
            SELECT COUNT(*) AS childNodesCount , p2.[ParentID] AS pId
            FROM [Products] p2
            GROUP BY p2.[ParentID]
            ) p3
            ON p1.[ProductID] = p3.pId
            WHERE p1.[ParentID] " + para;

                DataTable dt = OleDbHelper.ExecuteDataset( base.NorthWindConnectionString, CommandType.Text, sql ).Tables[0];

                ASTreeViewNode root = new ASTreeViewNode( "root" );

                foreach( DataRow dr in dt.Rows )
                {
                    string productName = dr["ProductName"].ToString();
                    string productId = dr["ProductID"].ToString();
                    string parentId = dr["ParentID"].ToString();
                    int childNodesCount = 0;
                    if( !string.IsNullOrEmpty( dr["ChildNodesCount"].ToString() ) )
                        childNodesCount = int.Parse( dr["ChildNodesCount"].ToString() );

                    ASTreeViewLinkNode node = new ASTreeViewLinkNode( productName, productId );
                    node.VirtualNodesCount = childNodesCount;
                    node.VirtualParentKey = productId;
                    node.IsVirtualNode = childNodesCount > 0;
                    node.NavigateUrl = "#";
                    node.AdditionalAttributes.Add( new KeyValuePair<string, string>( "onclick", "return false;" ) );

                    root.AppendChild( node );
                }

                HtmlGenericControl ulRoot = new HtmlGenericControl( "ul" );
                astvMyTree2.TreeViewHelper.ConvertTree( ulRoot, root, false );
                foreach( Control c in ulRoot.Controls )
                    c.RenderControl( writer );
            }
            else if( Request.QueryString["t2"] == "ajaxAdd" )
            {
                string addNodeText = Request.QueryString["addNodeText"];
                int parentNodeValue = int.Parse( Request.QueryString["parentNodeValue"] );

                string maxSql = "select max( productId ) from products";
                int max = (int)OleDbHelper.ExecuteScalar( base.NorthWindConnectionString, CommandType.Text, maxSql );
                int newId = max + 1;

                string sql = string.Format( @"INSERT INTO products( productid, Discontinued, productname, parentid ) values( {0} ,0, '{1}', {2})"
                    , max + 1, addNodeText.Replace( "'", "''" ), parentNodeValue );

                int i = OleDbHelper.ExecuteNonQuery( base.NorthWindConnectionString, CommandType.Text, sql );

                ASTreeViewNode root = new ASTreeViewNode( "root" );

                ASTreeViewLinkNode node = new ASTreeViewLinkNode( addNodeText, newId.ToString() );
                node.NavigateUrl = "#";
                node.AdditionalAttributes.Add( new KeyValuePair<string, string>( "onclick", "return false;" ) );

                root.AppendChild( node );

                HtmlGenericControl ulRoot = new HtmlGenericControl( "ul" );
                astvMyTree2.TreeViewHelper.ConvertTree( ulRoot, root, false );
                foreach( Control c in ulRoot.Controls )
                    c.RenderControl( writer );
            }
            else
                base.Render( writer );
        }
        protected override void Render(HtmlTextWriter writer)
        {
            if (Request.QueryString["t1"] == "ajaxLoad")
            {
                string virtualParentKey = Request.QueryString["virtualParentKey"];

                string para = string.Empty;                // "= 1";
                if (virtualParentKey == null)
                {
                    para = " is NULL";
                }
                else
                {
                    para = "=" + virtualParentKey;
                }

                string sql = @"SELECT p1.[ProductID] as ProductID, p1.[ProductName] as ProductName, p1.[ParentID] as ParentID, p3.childNodesCount as ChildNodesCount
FROM [Products] p1
LEFT OUTER JOIN 
(
	SELECT COUNT(*) AS childNodesCount , p2.[ParentID] AS pId 
	FROM [Products] p2
	GROUP BY p2.[ParentID]
) p3
ON p1.[ProductID] = p3.pId
WHERE p1.[ParentID] " + para;

                DataTable dt = OleDbHelper.ExecuteDataset(base.NorthWindConnectionString, CommandType.Text, sql).Tables[0];

                ASTreeViewNode root = new ASTreeViewNode("root");

                foreach (DataRow dr in dt.Rows)
                {
                    string productName     = dr["ProductName"].ToString();
                    string productId       = dr["ProductID"].ToString();
                    string parentId        = dr["ParentID"].ToString();
                    int    childNodesCount = 0;
                    if (!string.IsNullOrEmpty(dr["ChildNodesCount"].ToString()))
                    {
                        childNodesCount = int.Parse(dr["ChildNodesCount"].ToString());
                    }

                    ASTreeViewLinkNode node = new ASTreeViewLinkNode(productName, productId);
                    node.VirtualNodesCount = childNodesCount;
                    node.VirtualParentKey  = productId;
                    node.IsVirtualNode     = childNodesCount > 0;
                    node.NavigateUrl       = "#";
                    node.AdditionalAttributes.Add(new KeyValuePair <string, string>("onclick", "return false;"));

                    root.AppendChild(node);
                }



                HtmlGenericControl ulRoot = new HtmlGenericControl("ul");
                astvMyTree2.TreeViewHelper.ConvertTree(ulRoot, root, false);
                foreach (Control c in ulRoot.Controls)
                {
                    c.RenderControl(writer);
                }
            }
            else if (Request.QueryString["t2"] == "ajaxAdd")
            {
                string addNodeText     = Request.QueryString["addNodeText"];
                int    parentNodeValue = int.Parse(Request.QueryString["parentNodeValue"]);

                string maxSql = "select max( productId ) from products";
                int    max    = (int)OleDbHelper.ExecuteScalar(base.NorthWindConnectionString, CommandType.Text, maxSql);
                int    newId  = max + 1;

                string sql = string.Format(@"INSERT INTO products( productid, Discontinued, productname, parentid ) values( {0} ,0, '{1}', {2})"
                                           , max + 1, addNodeText.Replace("'", "''"), parentNodeValue);

                int i = OleDbHelper.ExecuteNonQuery(base.NorthWindConnectionString, CommandType.Text, sql);

                ASTreeViewNode root = new ASTreeViewNode("root");

                ASTreeViewLinkNode node = new ASTreeViewLinkNode(addNodeText, newId.ToString());
                node.NavigateUrl = "#";
                node.AdditionalAttributes.Add(new KeyValuePair <string, string>("onclick", "return false;"));

                root.AppendChild(node);

                HtmlGenericControl ulRoot = new HtmlGenericControl("ul");
                astvMyTree2.TreeViewHelper.ConvertTree(ulRoot, root, false);
                foreach (Control c in ulRoot.Controls)
                {
                    c.RenderControl(writer);
                }
            }
            else
            {
                base.Render(writer);
            }
        }
        protected override void Render(HtmlTextWriter writer)
        {
            if (this.Page.Request.QueryString["t1"] == "ajaxLoad")
            {
                #region ajaxLoad

                string virtualParentKey = this.Page.Request.QueryString["virtualParentKey"];

                string para = string.Empty;                // "= 1";
                if (virtualParentKey == null)
                {
                    para = " is NULL";
                }
                else
                {
                    para = "=" + virtualParentKey;
                }

                string sql = @"SELECT p1.[ProductID] as ProductID, p1.[ProductName] as ProductName, p1.[ParentID] as ParentID, p3.childNodesCount as ChildNodesCount
FROM [Products] p1
LEFT OUTER JOIN 
(
	SELECT COUNT(*) AS childNodesCount , p2.[ParentID] AS pId 
	FROM [Products] p2
	GROUP BY p2.[ParentID]
) p3
ON p1.[ProductID] = p3.pId
WHERE p1.[ParentID] " + para;

                DataTable dt = OleDbHelper.ExecuteDataset(this.NorthWindConnectionString, CommandType.Text, sql).Tables[0];

                ASTreeViewNode root = new ASTreeViewNode("root");

                foreach (DataRow dr in dt.Rows)
                {
                    string productName     = dr["ProductName"].ToString();
                    string productId       = dr["ProductID"].ToString();
                    string parentId        = dr["ParentID"].ToString();
                    int    childNodesCount = 0;
                    if (!string.IsNullOrEmpty(dr["ChildNodesCount"].ToString()))
                    {
                        childNodesCount = int.Parse(dr["ChildNodesCount"].ToString());
                    }

                    ASTreeViewLinkNode node = new ASTreeViewLinkNode(productName, productId);
                    node.VirtualNodesCount = childNodesCount;
                    node.VirtualParentKey  = productId;
                    node.IsVirtualNode     = childNodesCount > 0;
                    node.NavigateUrl       = "#";
                    node.AdditionalAttributes.Add(new KeyValuePair <string, string>("onclick", "return false;"));

                    root.AppendChild(node);
                }


                writer.Write(astvMyTree.AjaxResponseStartTag);

                HtmlGenericControl ulRoot = new HtmlGenericControl("ul");
                astvMyTree.TreeViewHelper.ConvertTree(ulRoot, root, false);
                foreach (Control c in ulRoot.Controls)
                {
                    c.RenderControl(writer);
                }


                writer.Write(astvMyTree.AjaxResponseEndTag);

                #endregion
            }
            else if (this.Page.Request.QueryString["t2"] == "ajaxAdd")
            {
                #region ajaxAdd

                string addNodeText     = this.Page.Request.QueryString["addNodeText"];
                int    parentNodeValue = int.Parse(this.Page.Request.QueryString["parentNodeValue"]);

                string maxSql = "select max( productId ) from products";
                int    max    = (int)OleDbHelper.ExecuteScalar(this.NorthWindConnectionString, CommandType.Text, maxSql);
                int    newId  = max + 1;

                string sql = string.Format(@"INSERT INTO products( productid, Discontinued, productname, parentid ) values( {0} ,0, '{1}', {2})"
                                           , max + 1, addNodeText.Replace("'", "''"), parentNodeValue);

                int i = OleDbHelper.ExecuteNonQuery(this.NorthWindConnectionString, CommandType.Text, sql);

                ASTreeViewNode root = new ASTreeViewNode("root");

                ASTreeViewLinkNode node = new ASTreeViewLinkNode(addNodeText, newId.ToString());
                node.NavigateUrl = "#";
                node.AdditionalAttributes.Add(new KeyValuePair <string, string>("onclick", "return false;"));

                root.AppendChild(node);


                writer.Write(astvMyTree.AjaxResponseStartTag);

                HtmlGenericControl ulRoot = new HtmlGenericControl("ul");
                astvMyTree.TreeViewHelper.ConvertTree(ulRoot, root, false);
                foreach (Control c in ulRoot.Controls)
                {
                    c.RenderControl(writer);
                }

                writer.Write(astvMyTree.AjaxResponseEndTag);

                #endregion
            }
            else
            {
                base.Render(writer);

                #region render click script

                string clickScript = string.Format(@"
<script type='text/javascript'>
function nodeSelectHandler{0}(elem){{
	document.getElementById('{1}').value = encodeURIComponent(elem.innerHTML);
	document.getElementById('{2}').value = elem.parentNode.getAttribute(""treeNodeValue"");
	document.getElementById('{3}').click();
}}
</script>"
                                                   , this.ClientID                     /*0*/
                                                   , this.hfSelectedNodeText.ClientID  /*1*/
                                                   , this.hfSelectedNodeValue.ClientID /*2*/
                                                   , this.btnPostBackTrigger.ClientID /*3*/);

                writer.Write(clickScript);

                #endregion
            }
        }
        protected override void Render(HtmlTextWriter writer)
        {
            if (Request.QueryString["t"] == "ajaxAdd")
            {
                string addNodeText     = HttpUtility.UrlDecode(Request.QueryString["addNodeText"]);
                int    parentNodeValue = int.Parse(HttpUtility.UrlDecode(Request.QueryString["parentNodeValue"]));

                string maxSql = "select max( productId ) from products";
                int    max    = (int)OleDbHelper.ExecuteScalar(base.NorthWindConnectionString, CommandType.Text, maxSql);
                int    newId  = max + 1;

                string sql = string.Format(@"INSERT INTO products( productid, Discontinued, productname, parentid ) values( {0} ,0, '{1}', {2})"
                                           , max + 1, addNodeText.Replace("'", "''"), parentNodeValue);

                int i = OleDbHelper.ExecuteNonQuery(base.NorthWindConnectionString, CommandType.Text, sql);

                ASTreeViewNode root = new ASTreeViewNode("root");

                ASTreeViewLinkNode node = new ASTreeViewLinkNode(addNodeText, newId.ToString());
                node.NavigateUrl = "#";
                node.AdditionalAttributes.Add(new KeyValuePair <string, string>("onclick", "return false;"));

                root.AppendChild(node);

                HtmlGenericControl ulRoot = new HtmlGenericControl("ul");
                astvMyTree.TreeViewHelper.ConvertTree(ulRoot, root, false);
                foreach (Control c in ulRoot.Controls)
                {
                    c.RenderControl(writer);
                }

                /*
                 * foreach( DataRow dr in dt.Rows )
                 * {
                 *      string productName = dr["ProductName"].ToString();
                 *      string productId = dr["ProductID"].ToString();
                 *      string parentId = dr["ParentID"].ToString();
                 *      int childNodesCount = 0;
                 *      if( !string.IsNullOrEmpty( dr["ChildNodesCount"].ToString() ) )
                 *              childNodesCount = int.Parse( dr["ChildNodesCount"].ToString() );
                 *
                 *      ASTreeViewLinkNode node = new ASTreeViewLinkNode( productName, productId );
                 *      node.VirtualNodesCount = childNodesCount;
                 *      node.VirtualParentKey = productId;
                 *      node.IsVirtualNode = childNodesCount > 0;
                 *      node.NavigateUrl = "#";
                 *      node.AdditionalAttributes.Add( new KeyValuePair<string, string>( "onclick", "return false;" ) );
                 *
                 *      root.AppendChild( node );
                 * }
                 *
                 *
                 *
                 * HtmlGenericControl ulRoot = new HtmlGenericControl( "ul" );
                 * astvMyTree.TreeViewHelper.ConvertTree( ulRoot, root, false );
                 * foreach( Control c in ulRoot.Controls )
                 *      c.RenderControl( writer );*/
            }
            else
            {
                base.Render(writer);
            }
        }
		protected override void Render( HtmlTextWriter writer )
		{
			if( this.Page.Request.QueryString["t1"] == "ajaxLoad" )
			{
				#region ajaxLoad

				string virtualParentKey = this.Page.Request.QueryString["virtualParentKey"];

				string para = string.Empty;// "= 1";
				if( virtualParentKey == null )
					para = " is NULL";
				else
					para = "=" + virtualParentKey;

				string sql = @"SELECT p1.[ProductID] as ProductID, p1.[ProductName] as ProductName, p1.[ParentID] as ParentID, p3.childNodesCount as ChildNodesCount
FROM [Products] p1
LEFT OUTER JOIN 
(
	SELECT COUNT(*) AS childNodesCount , p2.[ParentID] AS pId 
	FROM [Products] p2
	GROUP BY p2.[ParentID]
) p3
ON p1.[ProductID] = p3.pId
WHERE p1.[ParentID] " + para;

				DataTable dt = OleDbHelper.ExecuteDataset( this.NorthWindConnectionString, CommandType.Text, sql ).Tables[0];

				ASTreeViewNode root = new ASTreeViewNode( "root" );

				foreach( DataRow dr in dt.Rows )
				{
					string productName = dr["ProductName"].ToString();
					string productId = dr["ProductID"].ToString();
					string parentId = dr["ParentID"].ToString();
					int childNodesCount = 0;
					if( !string.IsNullOrEmpty( dr["ChildNodesCount"].ToString() ) )
						childNodesCount = int.Parse( dr["ChildNodesCount"].ToString() );

					ASTreeViewLinkNode node = new ASTreeViewLinkNode( productName, productId );
					node.VirtualNodesCount = childNodesCount;
					node.VirtualParentKey = productId;
					node.IsVirtualNode = childNodesCount > 0;
					node.NavigateUrl = "#";
					node.AdditionalAttributes.Add( new KeyValuePair<string, string>( "onclick", "return false;" ) );

					root.AppendChild( node );
				}


				writer.Write( astvMyTree.AjaxResponseStartTag );

				HtmlGenericControl ulRoot = new HtmlGenericControl( "ul" );
				astvMyTree.TreeViewHelper.ConvertTree( ulRoot, root, false );
				foreach( Control c in ulRoot.Controls )
					c.RenderControl( writer );


				writer.Write( astvMyTree.AjaxResponseEndTag );

				#endregion

			}
			else if( this.Page.Request.QueryString["t2"] == "ajaxAdd" )
			{
				#region ajaxAdd

				string addNodeText = this.Page.Request.QueryString["addNodeText"];
				int parentNodeValue = int.Parse( this.Page.Request.QueryString["parentNodeValue"] );

				string maxSql = "select max( productId ) from products";
				int max = (int)OleDbHelper.ExecuteScalar( this.NorthWindConnectionString, CommandType.Text, maxSql );
				int newId = max + 1;

				string sql = string.Format( @"INSERT INTO products( productid, Discontinued, productname, parentid ) values( {0} ,0, '{1}', {2})"
					, max + 1, addNodeText.Replace( "'", "''" ), parentNodeValue );

				int i = OleDbHelper.ExecuteNonQuery( this.NorthWindConnectionString, CommandType.Text, sql );

				ASTreeViewNode root = new ASTreeViewNode( "root" );

				ASTreeViewLinkNode node = new ASTreeViewLinkNode( addNodeText, newId.ToString() );
				node.NavigateUrl = "#";
				node.AdditionalAttributes.Add( new KeyValuePair<string, string>( "onclick", "return false;" ) );

				root.AppendChild( node );


				writer.Write( astvMyTree.AjaxResponseStartTag );

				HtmlGenericControl ulRoot = new HtmlGenericControl( "ul" );
				astvMyTree.TreeViewHelper.ConvertTree( ulRoot, root, false );
				foreach( Control c in ulRoot.Controls )
					c.RenderControl( writer );

				writer.Write( astvMyTree.AjaxResponseEndTag );

				#endregion
			}
			else
			{
				base.Render( writer );

				#region render click script

				string clickScript = string.Format( @"
<script type='text/javascript'>
function nodeSelectHandler{0}(elem){{
	document.getElementById('{1}').value = encodeURIComponent(elem.innerHTML);
	document.getElementById('{2}').value = elem.parentNode.getAttribute(""treeNodeValue"");
	document.getElementById('{3}').click();
}}
</script>"
					, this.ClientID /*0*/
					, this.hfSelectedNodeText.ClientID /*1*/
					, this.hfSelectedNodeValue.ClientID /*2*/
					, this.btnPostBackTrigger.ClientID /*3*/);

				writer.Write( clickScript );

				#endregion
			}

		}
		private void GenerateTree()
		{

			ASTreeViewLinkNode n = new ASTreeViewLinkNode( "Picasa", "Picasa", "http://picasaweb.google.com", "frm", "Goto Picasa", "~/Images/demoIcons/picasa.gif" );
			n.NodeText = "The node cannot have children.";
			n.EnableChildren = false;
			n.EnableEditContextMenu = false;

			//n.AdditionalAttributes.Add( new KeyValuePair<string, string>( "onclick", "alert(1);return false;" ) );
			//n.AdditionalAttributes.Add( new KeyValuePair<string, string>( "disableChildren1", "true" ) );

			this.astvMyTree.RootNode
				//.AppendChild( new ASTreeViewLinkNode( "Accor", "Accor", "http://www.accor.com", "frm", "Goto Accor", "~/Images/demoIcons/accor.gif" )
				//                    .AppendChild( new ASTreeViewLinkNode( "Accor Services", "Accor Services", "http://www.accorservices.com", "frm", "Goto Accor Services", "~/Images/demoIcons/accorservices.gif" ) )
				//                    .AppendChild( new ASTreeViewLinkNode( "Accor Hospitality", "Accor Hospitality", "http://www.accorhotels.com", "frm", "Goto Accor Hospitality", "~/Images/demoIcons/accorhospitality.gif" ) )
				//)
								.AppendChild( new ASTreeViewLinkNode( "GM", "GM", "http://www.gm.com", "frm", "Goto GM.com", "~/Images/demoIcons/gm.gif" )
													.AppendChild( new ASTreeViewLinkNode( "Hummer", "Hummer", "http://www.hummer.com", "frm", "Goto Hummer.com", "~/Images/demoIcons/hummer.gif" ) )
													.AppendChild( new ASTreeViewLinkNode( "Cadillac", "Cadillac", "http://www.cadillac.com", "frm", "Goto Cadillac.com", "~/Images/demoIcons/cadillac.gif" ) )
													.AppendChild( new ASTreeViewLinkNode( "SAAB", "SAAB", "http://www.saab.com", "frm", "Goto SAAB.com", "~/Images/demoIcons/saab.gif" ) )
								)
								.AppendChild( new ASTreeViewLinkNode( "Google", "Google Site", "http://www.google.com", "frm", "Goto Google", "~/Images/demoIcons/google.gif" )
													.AppendChild( new ASTreeViewLinkNode( "Picasa", "Picasa", "http://picasaweb.google.com", "frm", "Goto Picasa", "~/Images/demoIcons/picasa.gif" ) )
								)
								.AppendChild( new ASTreeViewLinkNode( "Microsoft", "Microsoft", "http://www.microsoft.com", "frm", "Goto Microsoft", "~/Images/demoIcons/microsoft.gif" )
													.AppendChild( new ASTreeViewLinkNode( "MSDN", "MSDN", "http://www.msdn.com", "frm", "Goto MSDN", "~/Images/demoIcons/msdn.gif" ) )
								)
								.AppendChild( new ASTreeViewLinkNode( "Amazon", "Amazon", "http://www.amazon.com", "frm", "Goto Amazon", "~/Images/demoIcons/amazon.gif" ).AppendChild( n ) )
								.AppendChild( new ASTreeViewLinkNode( "<font style='color:blue;font-weight:bold;font-style:italic;' isTreeNodeChild='true'>ASTreeView</font>", "Best Free TreeView Control for ASP.Net", "http://www.astreeview.com", "frm", "Html as TreeNode Text", "~/Images/demoIcons/ast.gif" )
								);



			/*
			string path = System.AppDomain.CurrentDomain.BaseDirectory;
			string connStr = string.Format( "Provider=Microsoft.Jet.OLEDB.4.0;Data source={0}db\\NorthWind.mdb", path );

			DataSet ds = OleDbHelper.ExecuteDataset( connStr, CommandType.Text, "select * from [Products]" );

			ASTreeViewDataTableColumnDescriptor descripter = new ASTreeViewDataTableColumnDescriptor( "ProductName"
				, "ProductID"
				, "ParentID" );
			//descripter.AddSingleQuotationOnQuery = false;
			this.astvMyTree.DataTableColumnDescriptor = descripter;
			this.astvMyTree.DataSource = ds.Tables[0];
			this.astvMyTree.DataBind();
			*/
		}