treevie刷新问题

achao201 2009-04-17 07:14:48
treeview想实现这个功能,点击父节点,就展开子节点,点击子节点用脚本传值。。。,但是用了Tv_SelectedNodeChanged方法,会回发页面,对其加了一个updatepanle后,tn.Expanded = true; 无效了,点击父节点展开不了子节点。。。


<%@ Page Language="C#" AutoEventWireup="true" CodeFile="product_type_sel.aspx.cs" Inherits="Business_center_Function_page_Product_mailpublish_product_type_sel" %>

<%@ Register assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" namespace="System.Web.UI" tagprefix="asp" %>

<!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 style="font-weight: 700">
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:TreeView ID="Tv" runat="server" ImageSet="Msdn"
onselectednodechanged="Tv_SelectedNodeChanged" ExpandDepth="1" NodeIndent="10"
ShowLines="True">
<ParentNodeStyle Font-Bold="False" />
<HoverNodeStyle Font-Underline="True" BackColor="#CCCCCC" BorderColor="#888888"
BorderStyle="Solid" />
<SelectedNodeStyle Font-Underline="False"
HorizontalPadding="3px" VerticalPadding="1px" BackColor="White"
BorderColor="#888888" BorderStyle="Solid" BorderWidth="1px" />
<NodeStyle Font-Names="Verdana" Font-Size="8pt" ForeColor="Black"
HorizontalPadding="5px" NodeSpacing="1px" VerticalPadding="2px" />
</asp:TreeView>




<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="Tv" EventName="SelectedNodeChanged">
</asp:AsyncPostBackTrigger>
</Triggers>
</asp:UpdatePanel>




</div>

</form>
</body>
</html>


using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

public partial class Business_center_Function_page_Product_mailpublish_product_type_sel : System.Web.UI.Page
{

DataSet dsTv;
private static string UserKind_Type = "01";
protected void Page_Load(object sender, EventArgs e)
{
if (this.IsPostBack == false)
{
string strName = Member.GetUserName() ;
UserKind_Type = (Request.QueryString["UserKind_Type"] != null) ? Request.QueryString["UserKind_Type"].ToString() : "01"; //默认是供应的产品类别,01供应,02为求购,04为未定义
if (!string.IsNullOrEmpty(strName))
{
BindTV(strName,UserKind_Type);
initTree(Tv.Nodes,"0");
}
}
}

private DataSet BindTV(string UserName, string UserKind_Type)
{
car2100.BLL.Enterprise.product_purvey_info bllPurvey = new car2100.BLL.Enterprise.product_purvey_info();
dsTv = bllPurvey.GetDataKind(UserName,UserKind_Type);
return dsTv;
}

public void initTree(System.Web.UI.WebControls.TreeNodeCollection nds, string ParentID)
{

DataView dv = new DataView();
dv.Table = dsTv.Tables[0];

dv.RowFilter = "ParentnID='" + ParentID + "'";
TreeNode tnd;
foreach(System.Data.DataRowView drv in dv)
{
tnd = new TreeNode();
tnd.Value = drv.Row["TypeCode"].ToString().Trim();
tnd.Text = drv.Row["TypeName"].ToString().Trim();

nds.Add(tnd);
string tn = tnd.Value;
initTree(tnd.ChildNodes, tn);
}

}

protected void Tv_SelectedNodeChanged(object sender, EventArgs e)
{
TreeNode tn = Tv.SelectedNode;
if (tn.ChildNodes.Count > 0)
{

tn.Expanded = true;

}
else
{
string nodeText = tn.Text.Trim();
string nodeValue = tn.Value.Trim();
string script = "";
if (UserKind_Type == "01")
{

script = "<script>window.parent.SetKind('" + nodeText + "','" + nodeValue + "');</script>";
}
else if (UserKind_Type == "04")
{

script = "<script>window.parent.SetProKind('" + nodeText + "','" + nodeValue + "'); </script>";
}


ScriptManager.RegisterStartupScript(Page, this.GetType(), "OpenKind", script, false);
}
}
}

...全文
60 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
jerrylyj 2009-04-17
  • 打赏
  • 举报
回复
我也碰到过这个问题,弄了好久也没办法,好像跟ajax冲突,就想viewstat跟ajax冲突一样,所以没办法我只要重新调用一次window.refresh...哈哈。强制刷新页面就行
yagebu1983 2009-04-17
  • 打赏
  • 举报
回复
三楼已经回答了。。。
接分。。。
achao201 2009-04-17
  • 打赏
  • 举报
回复
把treeview 放在updatepanel内,点连接图标会展不开节点。。。
阿非 2009-04-17
  • 打赏
  • 举报
回复
把treeview 放在updatepanel内

62,268

社区成员

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

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

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

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