protected void btnAdd2_Click(object sender, EventArgs e) { if (String.IsNullOrEmpty(tbItem2.Text)) { return; } string maxSql = string.Format("select max( productId ) from ProductsTree"); int max = (int)OleDbHelper.ExecuteScalar(base.NorthWindConnectionString, CommandType.Text, maxSql); int newId = max + 1; OleDbHelper.ExecuteNonQuery(base.NorthWindConnectionString, CommandType.Text, string.Format("INSERT INTO ProductsTree (ProductId, ProductName, ParentId,Username) VALUES({0}, '{1}', 0,'{2}')", newId, tbItem2.Text, Session["UserName"].ToString())); String qry = "select SUBSTRING([ProductName], 1, CASE CHARINDEX(CHAR(10), [ProductName]) WHEN 0 THEN LEN([ProductName]) ELSE CHARINDEX(char(10), [ProductName]) - 1 END) as ProductName from [ProductsTree] where ProductID=" + newId.ToString(); ASTreeViewNode newNode = new ASTreeViewNode((string)OleDbHelper.ExecuteScalar(base.NorthWindConnectionString, CommandType.Text, qry), newId.ToString()); ASTreeViewNode rootNode = astvMyTree2.FindByValue("root"); rootNode.AppendChild(newNode); XmlDocument doc = astvMyTree2.GetTreeViewXML(); doc.Save(Server.MapPath("~/" + Session["UserName"] + ".xml")); BindData(); }
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 void btnAdd_Click(object sender, EventArgs e) { /* * if (String.IsNullOrEmpty(tbItem.Text)) * return; */ string maxSql = string.Format("SELECT MAX(productId) from ProductsTree"); int max = (int)OleDbHelper.ExecuteScalar(base.NorthWindConnectionString, CommandType.Text, maxSql); int newId = max + 1; OleDbHelper.ExecuteNonQuery(base.NorthWindConnectionString, CommandType.Text, string.Format("INSERT INTO ProductsTree (ProductId, ProductName, ParentId, Username) VALUES({0},'{1}',{3},'{2}')", newId, "Untitled", Session["UserName"].ToString(), ddlRoot1.SelectedValue)); String qry = "SELECT SUBSTRING([ProductName], 1, CASE CHARINDEX(CHAR(10), [ProductName]) WHEN 0 THEN LEN([ProductName]) ELSE CHARINDEX(char(10), [ProductName]) - 1 END) as ProductName from [ProductsTree] where ProductID=" + newId.ToString(); ASTreeViewNode newNode = new ASTreeViewNode((string)OleDbHelper.ExecuteScalar(base.NorthWindConnectionString, CommandType.Text, qry), newId.ToString()); List <KeyValuePair <string, string> > attrib = new List <KeyValuePair <string, string> >(); ASTreeViewNode rootNode = astvMyTree1.FindByValue(ddlRoot1.Text); rootNode.AppendChild(newNode); XmlDocument doc = astvMyTree1.GetTreeViewXML(); doc.Save(Server.MapPath("~/" + ddlRoot1.SelectedValue + ".xml")); BindData(); }
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 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); } }
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 } }