Answered by:
tree view

Question
-
User-158363518 posted
hi every body
CREATE TABLE [dbo].[Consepts]( [idConsepts] [int] IDENTITY(1,1) NOT NULL, [idTeacher] [int] NULL, [idCourse] [int] NULL, [Subject] [nvarchar](50) NULL, [idParent] [int] NULL, CONSTRAINT [PK_Consepts] PRIMARY KEY CLUSTERED ( [idConsepts] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] ) ON [PRIMARY]
with this table How I can Bind Data In Tree View ?
please Giv me a sample For Insert In Table and Show In TreeView .
Thanks
Wednesday, June 1, 2016 7:00 AM
Answers
-
User61956409 posted
Hi csajad,
Firstly, you could fetch all parent nodes records (which idParent field is null) from database, then you could loop through parent nodes collection to create nodes , and at the same time you could query for child nodes records for each parent node.
In Insert Command I Need Selected Node (Parent ID ) In tree View .
I don't Know how to get that .
Secondly, you could try to use TreeView.SelectedNode.Parent to find the parent node of selected node.
Best Regards,
Fei Han
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Friday, June 3, 2016 7:52 AM
All replies
-
User1050679493 posted
Hi
have a look of the below links. it's having article to bind tree view from DB
http://www.dotnetfox.com/articles/binding-treeview-from-database-in-Asp-Net-1013.aspx
http://www.c-sharpcorner.com/uploadfile/krishnasarala/bind-treeview-from-a-database-in-Asp-Net/
Wednesday, June 1, 2016 8:11 AM -
User61956409 posted
Hi csajad,
please Giv me a sample For Insert In Table and Show In TreeView .Firstly, er.vks has shared us some links that explained how to bind tree view control, please refer to the links.
Secondly, if you’d like to insert records into database from code behind, you could refer to this article using SqlConnection and SqlCommand object to execute a insert query.
http://www.c-sharpcorner.com/blogs/easy-steps-to-insert-data-into-sql-server-using-asp-netc-sharp1
Best Regards
Fei Han
Wednesday, June 1, 2016 10:03 AM -
User-158363518 posted
They Used Two Tables But I Used One .
In Insert Command I Need Selected Node (Parent ID ) In tree View .
I don't Know how to get that .
If parent Id is Null = father else Is Child
Wednesday, June 1, 2016 10:41 AM -
User61956409 posted
Hi csajad,
Firstly, you could fetch all parent nodes records (which idParent field is null) from database, then you could loop through parent nodes collection to create nodes , and at the same time you could query for child nodes records for each parent node.
In Insert Command I Need Selected Node (Parent ID ) In tree View .
I don't Know how to get that .
Secondly, you could try to use TreeView.SelectedNode.Parent to find the parent node of selected node.
Best Regards,
Fei Han
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Friday, June 3, 2016 7:52 AM -
User768703680 posted
Hi,
Please try the below mentioned code,
foreach (DataRow c in dtTree) { TreeNode ParentNode = new TreeNode(); ParentNode.Text = c.StudentID; ParentNode.Value = c.StudentID; TreeView1.Nodes.Add(ParentNode); List<NewStudent> list2 = dal.FindAll(); foreach (DataRow d in dtTree.Select("control_Type = " + c.id)) { TreeNode ChildNode = new TreeNode(); ChildNode.Text = d.StudentID; ChildNode.Value = d.StudentID; ParentNode.ChildNodes.Add(ChildNode); } }
Friday, June 3, 2016 12:13 PM