Bind Treeview in asp.net c# using dataset
HTML code treeview in asp.net :
C# Code treeview control in asp.net :
For Check / Uncheck Checkboxes in treeview control using jquery you can visit following post :- Check / Uncheck Checkboxes in treeview control using jquery
Introduction : In this article i will show you how to bind treeview in c# using dataset . I have created complete code to bind the treeview and also table structure in image which require for the treeview control to bind in asp.net c# using dataset .
Table structure :HTML code treeview in asp.net :
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="TreeViewControl.aspx.cs" Inherits="HamidSite.TreeViewControl" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> </head> <body> <form id="form1" runat="server"> <div> <asp:TreeView ID="treeviwExample" runat="server" ImageSet="Arrows"> <HoverNodeStyle Font-Underline="True" ForeColor="#5555DD" /> <NodeStyle Font-Names="Verdana" Font-Size="8pt" ForeColor="Black" HorizontalPadding="5px" NodeSpacing="0px" VerticalPadding="0px" /> <ParentNodeStyle Font-Bold="False" /> <SelectedNodeStyle Font-Underline="True" ForeColor="#5555DD" HorizontalPadding="0px" VerticalPadding="0px" /> </asp:TreeView> </div> </form> </body> </html>
C# Code treeview control in asp.net :
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Data; using System.Data.SqlClient; namespace HamidSite { public partial class TreeViewControl : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { BindTreeViewControl(); } } private void BindTreeViewControl() { try { DataSet ds = GetDataSet("Select ProductId,ProductName,ParentId from ProductTable"); DataRow[] Rows = ds.Tables[0].Select("ParentId IS NULL"); // Get all parents nodes for (int i = 0; i < Rows.Length; i++) { TreeNode root = new TreeNode(Rows[i]["ProductName"].ToString(), Rows[i]["ProductId"].ToString()); root.SelectAction = TreeNodeSelectAction.Expand; CreateNode(root, ds.Tables[0]); treeviwExample.Nodes.Add(root); } } catch (Exception Ex) { throw Ex; } } public void CreateNode(TreeNode node , DataTable Dt) { DataRow[] Rows = Dt.Select("ParentId =" + node.Value); if (Rows.Length == 0) { return; } for (int i = 0; i < Rows.Length; i++) { TreeNode Childnode = new TreeNode(Rows[i]["ProductName"].ToString(), Rows[i]["ProductId"].ToString()); Childnode.SelectAction = TreeNodeSelectAction.Expand; node.ChildNodes.Add(Childnode); CreateNode(Childnode, Dt); } } private DataSet GetDataSet(string Query) { DataSet Ds = new DataSet(); try { string strCon = @"Data Source=Servername;Initial Catalog=Test;Integrated Security=True"; SqlConnection Con = new SqlConnection(strCon); SqlDataAdapter Da = new SqlDataAdapter(Query, Con); Da.Fill(Ds); } catch (Exception) { } return Ds; } } }
For Check / Uncheck Checkboxes in treeview control using jquery you can visit following post :- Check / Uncheck Checkboxes in treeview control using jquery
i
ReplyDeleteHi All,
ReplyDeleteI have a table as same with this article and I have a table another with ProductId as Foreign Key also as ParentId. Example:
Table A
Id(PK) | ParentId | Name
1 0 Apple
2 0 Dell
3 0 Asus
4 1 Apple 001
5 1 Apple 002
6 2 Dell 001
7 2 Dell 002
8 3 Asus 001
9 3 Asus 002
Table B
Id(PK) | AId(FK) | Color
1 4 Bule
2 5 Black
3 6 White
4 7 Red
5 8 Pink
6 9 Yellow
How can I Bind Treeview in asp.net c# using dataset?Thanks!
how to delete nodes from treeview on a button click bind to dataset??
ReplyDeleteplzz can anyone help
i have used code from this example
ReplyDeleteHi,
ReplyDeleteWell done,
How do i change all parents check state when a child is selected(enable three state),
like this http://www.jeasyui.com/tutorial/tree/tree4.php
can anyone help me?
thanks in advance.
Hey,really excellent article,it worked out, thanks a lot, more than 2 weeks i was struggling witha tree view , my problem got solved, keep it up, DUDE
ReplyDeleteand to pass the values in #SelectedNodeChanged event
just add this line:Childnode.SelectAction = TreeNodeSelectAction.Select;
instead of expand give select;
This comment has been removed by a blog administrator.
ReplyDeletenice blog
ReplyDeleteDental treatment
Dental implants in India
Dental clinic in gurgaon
Cosmetic dentist in gurgaon
Gums treatment clinic in delhi
root canal treatment
Nice blog
ReplyDeletebest dental treatment
dental tourism in India
best Dentist in gurgaon
best cosmetic dentist
root canal treatment in delhi
bleeding gums treatment
This comment has been removed by a blog administrator.
ReplyDeleteNot working for me.
ReplyDeleteThank u a lot..its very useful..
ReplyDeletehi,
ReplyDeletethx a LoT
its working smooth and fine
C# binding TreeView to database table
ReplyDeletethank you so much, your code is working now ^_^
ReplyDeleteHi,
ReplyDeleteThis was very help full to me.
Thank you :)
GOOD LOGIC FOR THE DEVELOPERS WHO WANT TO IMPLEMENT THIS STRATEGY :)
ReplyDeleteis there any possibility that whn node get clicked we get the messagebox
ReplyDeleteits really very urgent i have used this code but i get stucked in node event fired
ReplyDeleteThanx bro.... Please continue your posting...
ReplyDeleteit is not work
ReplyDeletethanks buddy..
ReplyDeleteits really great...
can anyone tell me that how can i get all childs nodes for particular parent....
its urgent........
can anyone tell me that how can i get all childs nodes for particular parent....
ReplyDeleteits urgent........
I never expected such a fantastic response to this query. Your solution is far superior to mine--just what I was looking for.
ReplyDeletePackers and Movers Pondicherry
Kabera Global hair transplant is providing
ReplyDeleteThe Best Hair Transplant in Delhi at best cost available in the Capital city. We have top hair transplant surgeons in our panel in Delhi.
This comment has been removed by the author.
ReplyDeleteHair Transplant In Chandigarh Kabera global provide Hair Transplant service in Chandigarh at Affordable price.It gives treatment nearby your location. It provide best solution according to your budget and requirement.
ReplyDeleteLove it , it helped me a lot, thanks
ReplyDeleteWhere we find that control HamidSite.TreeViewControl
ReplyDeleteGood post, do you have any others on this topic?
ReplyDeleteHair Transplant in Delhi
Hair transplant in pune It is a good article post.Thanks for sharing.
ReplyDeleteBuy the different sizes of iv cannula like 14g to 26g from mais india, For more details visit our website -https://maisindia.com/ivcannula
ReplyDeleteMais India | IV Cannula | Safety IV Cannula
marsbahisbetboo
ReplyDeletesultanbet
marsbahis
betboo
sultanbet
binance güvenilir mi
ReplyDeleteinstagram takipçi satın al
takipçi satın al
instagram takipçi satın al
shiba coin hangi borsada
shiba coin hangi borsada
tiktok jeton hilesi
is binance safe
is binance safe
smm panel
ReplyDeleteSMM PANEL
isilanlariblog.com
instagram takipçi satın al
HİRDAVATCİ
Https://www.beyazesyateknikservisi.com.tr/
servis
TİKTOK HİLE İNDİR