The text of this article is not in this database — only its details are. Read it on the old site: TreeView Control in ASP.NET
11 Comments
Join the conversation! Your thoughts help the community grow.
Sign in to leave a comment.
The text of this article is not in this database — only its details are. Read it on the old site: TreeView Control in ASP.NET
Join the conversation! Your thoughts help the community grow.
Sign in to leave a comment.
Vivek Kumar VishwasPosted Nov 10, 2017, 2:38 AM
Suppose , i have a table in database. I want to bind The unique id and name in nodes and when i click on node , it must show the all data according to that id by expanding the nodes. How to do this. ASpx Code --------------------------------<asp:TreeView ID="TreeView2" runat="server" ImageSet="XPFileExplorer" NodeIndent="15" Expanded="True" > <HoverNodeStyle Font-Underline="True" ForeColor="#6666AA" /> <NodeStyle Font-Names="Tahoma" Font-Size="8pt" ForeColor="Black" HorizontalPadding="2px" NodeSpacing="0px" VerticalPadding="2px"></NodeStyle> <ParentNodeStyle Font-Bold="False" /> <SelectedNodeStyle BackColor="#B5B5B5" Font-Underline="False" HorizontalPadding="0px" VerticalPadding="0px" /> </asp:TreeView> CS code--------------------------------SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["constr"].ConnectionString.ToString()); protected void Page_Load(object sender, EventArgs e) { if (!this.IsPostBack) { DataTable dt = this.GetData("SELECT * FROM TopParent"); this.PopulateTreeView(dt, 0, null); BindRepeaterRight(); } } private void PopulateTreeView(DataTable dtParent, int parentId, TreeNode treeNode) { foreach (DataRow row in dtParent.Rows) { TreeNode child = new TreeNode { Text = row["cName"].ToString(), Value = row["cId"].ToString() }; if (parentId == 0) { TreeView2.Nodes.Add(child); DataTable dtChild = this.GetData("SELECT * FROM TopParent WHERE Id = " + child.Value); PopulateTreeView(dtChild, int.Parse(child.Value), child); } else { treeNode.ChildNodes.Add(child); } } } private DataTable GetData(string query) { DataTable dt = new DataTable(); string constr = ConfigurationManager.ConnectionStrings["constr"].ConnectionString; using (SqlConnection con = new SqlConnection(constr)) { using (SqlCommand cmd = new SqlCommand(query)) { using (SqlDataAdapter sda = new SqlDataAdapter()) { cmd.CommandType = CommandType.Text; cmd.Connection = con; sda.SelectCommand = cmd; sda.Fill(dt); } } return dt; } }
cai huPosted Mar 11, 2014, 11:25 PM
thanks a lot for sharing. but i cann't to download the TreeViewExample.zip, Who can help me?
MayilrajanPosted Feb 13, 2014, 4:38 AM
good work...
Rajnish AzadPosted Feb 10, 2014, 1:51 AM
very nice article for tree view and sql server structure display. thanks .
ronel gonzalesPosted Oct 10, 2013, 11:05 PM
thanks a lot is very helpful
saagar soniPosted Sep 11, 2013, 2:16 AM
thanx a lot for sharing...very easy explanation
baskarPosted May 18, 2013, 9:54 AM
Where is Database file?
bassam mossaPosted Oct 21, 2012, 11:17 AM
can you make the same exp using vb.net and i need to use checkbox node in treeview
seenivasan PPosted Oct 4, 2012, 2:46 AM
Give same set of process using XML Database...
SenthilkumarPosted Mar 12, 2012, 11:53 PM
Thanks amit for your appreciation...
Amit MaheshwariPosted Mar 12, 2012, 1:02 PM
Good work senthilkumar keep it up and thanks for sharing........