NOTE :TreeView1 is the id of treeview and in dt1 has 100 records which it gets from database.
PopulateNodes(dt1, TreeView1.Nodes);
private void PopulateNodes(DataTable dt, TreeNodeCollection nodes)
{
foreach (DataRow dr in dt.Rows)
{
TreeNode tn = new TreeNode();
tn.Text = dr["columnfield"].ToString().Trim();
tn.Value = dr["code_webcategory_id"].ToString().Trim();
tn.ImageUrl = string.Format("image.aspx?category={0}&width=50", tn.Value);
nodes.Add(tn);
tn.PopulateOnDemand = (Convert.ToInt32(dr["childnodecount"]) > 0);
}
}
The above coding works fine.
NOTE: image.aspx, image comes from database(which comes as byte) and then writting as image using System.Drawing.Image bitmap = System.Drawing.Image.FromStream(stream),......the image comes from database and binds in tn.imageurl correctly. but here once the populateNodes function gets over only, the image.aspx calls to get image accordiing to node.
so, right now as i have 100 records it binds image 100 time which is ok.
now the below coding to bind child notes
private void PopulateSubLevel(int parentid, TreeNode parentNode)
{
TreeNode parent= parentNode;
PopulateNodes(dt, parent.ChildNodes);
}
this also works fine. but,
Now, consider the child node has 10 records. once the populateNodes function gets over , it calls image.aspx to get an image. Now it binds 110 time again instead of binding 10 times.
this is the problem. how to overcome? any solution? help needed.