Bind Treeview control Recursivley

//Page Load Event

UltraWebTree1.Nodes.Clear();
Infragistics.WebUI.UltraWebNavigator.Node node1 = new Infragistics.WebUI.UltraWebNavigator.Node();
//=new Infragistics.WebUI.UltraWebNavigator.Node("ASP.NetSearchDNN");
node1.Text = "Agencies";
UltraWebTree1.Nodes.Add(node1);
//TreeNode tNode = new TreeNode();
Infragistics.WebUI.UltraWebNavigator.Nodes tNode;
tNode = UltraWebTree1.Nodes[0].Nodes;
PopulateTreeView("0", tNode);
UltraWebTree1.ExpandAll();


//Recursive function


public void PopulateTreeView(string iparentId, Infragistics.WebUI.UltraWebNavigator.Nodes inTreeNode)
{
DataSet DSNASPSearch = new DataSet();
string strquery = "";
if (iparentId == "0")
{
strquery = "select ID ,OrganizationName,ParentId from tblAgencies where ParentId is null";
}
else
{
strquery = "select ID ,OrganizationName,ParentId from tblAgencies where ParentId= " + iparentId;
}
SqlDataAdapter da = new SqlDataAdapter(strquery, con);
da.Fill(DSNASPSearch, "tblAgencies");
// DataRow parentrow;
DataTable parenttable;
parenttable = DSNASPSearch.Tables["tblAgencies"];
foreach (DataRow parentrowin in parenttable.Rows)
{
Infragistics.WebUI.UltraWebNavigator.Node parentnode=new Infragistics.WebUI.UltraWebNavigator.Node();
string strlable = parentrowin[1].ToString() + parentrowin[2].ToString();
parentnode.Text = parentrowin[1].ToString();
parentnode.Tag = parentrowin[0].ToString();
//parentnode.Add(strlable);
inTreeNode.Add(parentnode);
PopulateTreeView(parentrowin[0].ToString(), parentnode.Nodes);
}

Comments

Popular posts from this blog

OutSystems – A Low-code Development Platform

What is difference between Azure Cognitive Search and Elastic Search

failed to access iis metabase asp.net