如何解决这个错误。图像网址在树视图中一次又一次地绑定 [英] How to solve this error. image url is binding again and again in treeview

查看:32
本文介绍了如何解决这个错误。图像网址在树视图中一次又一次地绑定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

注意:TreeView1是树视图的id,在dt1中有100条从数据库中获取的记录。



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);

	}


        }



上述编码工作正常。



注意:image.aspx,图像来自数据库(以字节形式出现),然后使用System.Drawing.Image bitmap = System.Drawing.Image写入图像.FromStream(stream),......图像来自数据库并正确绑定在tn.imageurl中。但是这里只有populateNodes函数过了,image.aspx调用才能获得符合节点的图像。



所以,现在因为我有100条记录它绑定图像100次,这是好的。



现在以下编码绑定儿童笔记


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);


 }



这也可行。但是,



现在,考虑子节点有10条记录。一旦populateNodes函数结束,它就会调用image.aspx来获取图像。现在它再次绑定110次而不是绑定10次。



这就是问题所在。怎么克服?任何解决方案需要帮助。


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.

推荐答案

这篇关于如何解决这个错误。图像网址在树视图中一次又一次地绑定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆