Hi naz, this is coding.
aspx;
<asp:Content ID="fintree" runat="server" ContentPlaceHolderID="em">
<div style="overflow:scroll; width:200px; height:1000px;">
<asp:TreeView ID="ModuleTreeView" ExpandDepth="0" runat="server" ShowLines="true" PopulateNodesFromClient="True"
BackColor="#FFFFFF" style="width:300%" ForeColor="Black" HoverNodeStyle-ForeColor="BlueViolet"
ShowExpandCollapse="true" PopulateOnDemand="true" NodeWrap="true" >
</asp:TreeView>
</div>
aspx.cs
namespace ShopGear1.View
{
public partial class treefin : System.Web.UI.Page
{
private string scon = "";
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
scon = System.Web.Configuration.WebConfigurationManager.ConnectionStrings["sqlconnectstring"].ConnectionString;
//ModuleTreeView.CollapseAll();
FillTreeView();
}
}
public DataTable GetModuleDetails()
{
using (SqlConnection conn = new SqlConnection(scon))
{
string sql = ""query;
SqlDataAdapter da = new SqlDataAdapter(sql, conn);
DataTable dt = new DataTable();
da.Fill(dt);
return dt;
}
}
public void FillTreeView()
{
DataTable modules = new DataTable();
modules = GetModuleDetails();
ModuleTreeView.Nodes.Clear();
PopulateTreeNode(modules, null, 0);
}
private void PopulateTreeNode(DataTable modulelist, TreeNode parent, int parentid)
{
TreeNodeCollection baseNodes;
TreeNode node;
if (parent == null)
{
baseNodes = ModuleTreeView.Nodes;
}
else
{
baseNodes = parent.ChildNodes;
}
foreach (DataRow dtrow in modulelist.Rows)
{
if (int.Parse(dtrow["parent_orid"].ToString()) == parentid)
{
node = new TreeNode();
node.Text = dtrow["descript"].ToString();
node.Value = dtrow["code_webcategory_id"].ToString();
//string ID = node.Value.ToString().Trim();
node.SelectAction = TreeNodeSelectAction.Select;
node.ImageUrl = string.Format("~/View/iw.aspx?category={0}&width=50", node.Value);
baseNodes.Add(node);
PopulateTreeNode(modulelist, node, int.Parse(dtrow["code_webcategory_id"].ToString()));
}
}
//ModuleTreeView.CollapseAll();
}
}
}