treeview展开保持的问题,想不通

michael_monkey 2008-11-11 03:24:18
页面很简单:一个updatepanel里面有一个LinkButton,和一个treeview
实现的功能是:点击LinkButton后调用方法showtree动态取得产品结构数据显示在treeview中

test.aspx:

<asp:UpdatePanel ID="UpdatePanel3" runat="server">
<ContentTemplate>

<asp:LinkButton ID="LinkButton1" runat="server" OnClick="LinkButton1_Click">LinkButton</asp:LinkButton><br />

<asp:TreeView ID="tv1" runat="server">
<Nodes>
<asp:TreeNode Text="请选择……" Value="-1"></asp:TreeNode>
</Nodes>
</asp:TreeView>

</ContentTemplate>
</asp:UpdatePanel>


test.vb:
…………
Protected Sub LinkButton1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
showTree(62)
End Sub


问题:

当对点击LinkButton生成的树进行选择操作,引发updatepanel更新后,treeview不能保持节点的展开状态,能保持选中状态。

但是如果在page_load里面调用showtree(62)生成结构树,则没有问题(既能保持选中状态,也能保持展开状态)
If Not Page.IsPostBack Then
showTree(62)
End If



我想不通这两者有啥区别,都是执行一次,页面回发时都不重建结构树的呀
...全文
433 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
qthl004 2012-08-06
  • 打赏
  • 举报
回复
楼主说的是不是这个软件?

关键字:

ASP TreeView非常快速并且非常小(only 44 KB) 的.Net Treeview控件. 易于使用并且样式丰富,并且你还可以自己设置节点的HTML标签Basic版本(小于20个节点)免费!
此产品包含在产品集合 obout components Suite 中。

More Features:


From/To XML file
Populate from XML file with one line of code
Loading Web style
WhiteR style
XpBlue style
Gray style
TsMenu style
Open in Search pane
Find Selected Node
From Dennis
Checkboxes
How To add checkboxes
Select multiple nodes
Show File System
File System Loading
Edit nodes
Keyboard Navigation
Icons for treeview
Customize
How-To and Help

ASP TreeView Vista Theme

michael_monkey 2008-11-11
  • 打赏
  • 举报
回复
我有做了另外的测试:
我在updatepanel外面加了按钮btn1,仍然执行showTree(62),然后对treeview的选择展开操作,正常:既能保持选中状态,也能保持展开状态。

再进一步:
另外加了一个updatepanel,然后把btn1拖到里边——结果:不正常(只能保持选中状态,不能保持展开状态。)



我想可以得出一个结论:
当treeview在updatepanel里面时,
不在updatepanel里面的事件或操作给treeview绑定数据,其后对treeview的选择、展开操作能保持其展开状态;
在updatepanel里面的事件或操作给treeview绑定数据,其后对treeview的选择、展开操作不能保持其展开状态。
两种情况下都能保持其选中状态。



所以我认为不是不能在updatepanel里放treeview,关键是要选对treeview填充数据的时机


最后还是那个疑问:在本例中,在updatepanel里面和外边给treeview填充数据有什么区别吗?从结果看,显而易见是有区别的,但是在哪儿?
gengwanshanreally 2008-11-11
  • 打赏
  • 举报
回复
学习,帮顶!
  • 打赏
  • 举报
回复
我记得很清楚,曾经确认过TreeView、Menu这两个控件不能放在UpdatePanel中。不知道现在SP1有没有解决。如果你找不到分析了TreeView源代码的人的分析,就不要把TreeView方法UpdatePanel中。TreeView本身可以支持客户端回调技术来Ajax方式动态加载子节点,只是需要设置一两个特殊属性而已。

http://www.google.cn/search?hl=zh-CN&newwindow=1&rls=com.microsoft%3A*%3AIE-SearchBox&rlz=1I7GGIJ&q=treeview+updatepanel&btnG=Google+%E6%90%9C%E7%B4%A2&meta=&aq=f&oq=
michael_monkey 2008-11-11
  • 打赏
  • 举报
回复
人呢?

看看啦
michael_monkey 2008-11-11
  • 打赏
  • 举报
回复
Imports System.Data.SqlClient
Imports System.Web.Configuration

Partial Class t2
Inherits System.Web.UI.Page

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not Page.IsPostBack Then
'showTree(62) '如果是这里对treeview填充数据,则对treeview的操作既能保持选中状态,也能保持展开状态
End If
End Sub

Sub showTree(ByVal sid As Integer)
'这里省略,我相信问题肯定不出在这儿
End Sub

Protected Sub LinkButton1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
showTree(62) '如果是这里对treeview填充数据,则对treeview的操作只能保持选中状态,不能保持展开状态
End Sub
End Class
michael_monkey 2008-11-11
  • 打赏
  • 举报
回复
t2.aspx:

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="t2.aspx.vb" Inherits="t2" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>无标题页</title>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel3" runat="server">
<ContentTemplate>
<asp:LinkButton ID="LinkButton1" runat="server" OnClick="LinkButton1_Click">LinkButton</asp:LinkButton><br />
<asp:TreeView ID="tv1" runat="server">
<Nodes>
<asp:TreeNode Text="请选择……" Value="-1"></asp:TreeNode>
</Nodes>
</asp:TreeView>
</ContentTemplate>
</asp:UpdatePanel>
</form>
</body>
</html>





t2.aspx.vb:
Imports System.Data.SqlClient
Imports System.Web.Configuration

Partial Class t2
Inherits System.Web.UI.Page

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not Page.IsPostBack Then
'showTree(62)
End If
End Sub

Sub showTree(ByVal sid As Integer)
'这里省略,我相信问题肯定不出在这儿
End Sub

Protected Sub LinkButton1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
showTree(62)
End Sub
End Class





以上是完整代码,我觉得非常郁闷,不知道问题出哪儿了
hy_lihuan 2008-11-11
  • 打赏
  • 举报
回复
还是没有看明白,如果你调用的程序没有问题的话,应该是一样的;你调试一下看看执行顺序就知道问题在哪里了

62,046

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧