I have created a treeview, which is binding categories and subcategories from database.
I want to display an icon (image) on left side of the treeview. For example, in treeview I have categories such as amana tool as a parent node and the router bits as child node of amana tool. So, in database I have icon of amana tool as well as icon of router bits. Now, I am able to show categories (amana tool) only in treeview. But, I need that left side should show the icon of the related categories and then categories name(amana tool).
Note: The icon should bind from database but it should not be static icon because I need to show more than 100 categories and the icon existing in database.
Please help me out.
Here my code works correctly , further what i have to do?
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 ShopGear1.View
{
public partial class treefin : System.Web.UI.Page
{
private string scon = "";
protected void Page_Load(object sender, EventArgs e)
{
scon = " connection string";
ModuleTreeView.CollapseAll();
FillTreeView();
}
public DataTable GetModuleDetails()
{
using (SqlConnection conn = new SqlConnection(scon))
{
string sql = "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();
node.SelectAction = TreeNodeSelectAction.Select;
baseNodes.Add(node);
PopulateTreeNode(modulelist, node, int.Parse(dtrow["code_webcategory_id"].ToString()));
}
}
ModuleTreeView.CollapseAll();
}
}
}