تقييمات الطلاب
( 5 من 5 )
١ تقييمات
فيديو شرح Part 164 Displaying organization employee chart using treeview control in asp net ضمن كورس ASP.net شرح قناة kudvenkat، الفديو رقم 164 مجانى معتمد اونلاين
Text version of the video
http://csharp-video-tutorials.blogspot.com/2013/11/part-164-displaying-organization.html
Healthy diet is very important both for the body and mind. If you like Aarvi Kitchen recipes, please support by sharing, subscribing and liking our YouTube channel. Hope you can help.
https://www.youtube.com/channel/UC7sEwIXM_YfAMyonQCrGfWA/?sub_confirmation1
Slides
http://csharp-video-tutorials.blogspot.com/2014/10/displaying-organigation-employee-chart.html
All ASP .NET Text Articles
http://csharp-video-tutorials.blogspot.com/p/free-aspnet-video-tutorial.html
All ASP .NET Slides
http://csharp-video-tutorials.blogspot.com/p/aspnet-slides.html
ASP.NET Playlist
https://www.youtube.com/playlist?listPL4cyC4G0M1RQcB4IYS_zwkyBwMyx5AnDM
All Dot Net and SQL Server Tutorials in English
https://www.youtube.com/user/kudvenkat/playlists?view1&sortdd
All Dot Net and SQL Server Tutorials in Arabic
https://www.youtube.com/c/KudvenkatArabic/playlists
treeview control with checkbox in asp.net c#
In this video, we will discuss, displaying organization employee chart using treeview control. A check box should be displayed next to every TreeNode. On clicking the button, the selected employees must be added to the listbox.
SQL script to create and populate table tblEmployee
Create table tblEmployee
(
ID int identity primary key,
Name nvarchar(50),
ManagerId int foreign key references tblEmployee(ID)
)
Insert into tblEmployee values('David', NULL)
Insert into tblEmployee values('Sam', 1)
Insert into tblEmployee values('Pam', 1)
Insert into tblEmployee values('Mike', 1)
Insert into tblEmployee values('John', 2)
Insert into tblEmployee values('Tara', 2)
Insert into tblEmployee values('Todd', 4)
Stored procedure to retrieve data from table tblEmployee
Create Proc spGetEmployees
as
Begin
Select ID, Name, ManagerId from tblEmployee
End
Code:
namespace WebFormsDemo
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
GetTreeViewItems();
}
}
private void GetTreeViewItems()
{
string cs ConfigurationManager.ConnectionStrings["DBCS"].ConnectionString;
SqlConnection con new SqlConnection(cs);
SqlDataAdapter da new SqlDataAdapter("spGetEmployees", con);
DataSet ds new DataSet();
da.Fill(ds);
ds.Relations.Add("ChildRows", ds.Tables[0].Columns["ID"],
ds.Tables[0].Columns["ManagerId"]);
foreach (DataRow level1DataRow in ds.Tables[0].Rows)
{
if (string.IsNullOrEmpty(level1DataRow["ManagerId"].ToString()))
{
TreeNode parentTreeNode new TreeNode();
parentTreeNode.Text level1DataRow["Name"].ToString();
parentTreeNode.Value level1DataRow["ID"].ToString();
GetChildRows(level1DataRow, parentTreeNode);
TreeView1.Nodes.Add(parentTreeNode);
}
}
}
private void GetChildRows(DataRow dataRow, TreeNode treeNode)
{
DataRow[] childRows dataRow.GetChildRows("ChildRows");
foreach (DataRow row in childRows)
{
TreeNode childTreeNode new TreeNode();
childTreeNode.Text row["Name"].ToString();
childTreeNode.Value row["ID"].ToString();
treeNode.ChildNodes.Add(childTreeNode);
if (row.GetChildRows("ChildRows").Length GREATERTHAN_SYMBOL 0)
{
GetChildRows(row, childTreeNode);
}
}
}
protected void Button1_Click(object sender, EventArgs e)
{
ListBox1.Items.Clear();
GetSelectedTreeNodes(TreeView1.Nodes[0]);
}
private void GetSelectedTreeNodes(TreeNode parentTreeNode)
{
if (parentTreeNode.Checked)
{
ListBox1.Items.Add(parentTreeNode.Text + " - " + parentTreeNode.Value);
}
if (parentTreeNode.ChildNodes.Count GREATERTHAN_SYMBOL 0)
{
foreach (TreeNode childTreeNode in parentTreeNode.ChildNodes)
{
GetSelectedTreeNodes(childTreeNode);
}
}
}
}
}