您的位置:首页 > 编程语言 > ASP

TreeView无刷新动态生成树[C# Asp.net 2.0]

2008-08-23 21:30 711 查看
public partial class AdvAcordTree : System.Web.UI.Page
{
SysInfo sysInfo = new SysInfo();
DES des = new DES();
string patid;
DataSet ds; protected void Page_Load(object sender, EventArgs e)
{
patid = Request["patid"];
if (ds == null)
{
ds = new AdvAcord().GetMenuTree(sysInfo.ActDeptId, sysInfo.StaffId);
}
if (!IsPostBack)
{
TreeInit();
} } /// <summary>
/// 无刷新动态生成树
/// </summary>
private void TreeInit()
{
this.Tvtree.Nodes.Clear();

//添加个人模板
TreeNode node = new TreeNode("本人", "30");
node.SelectAction = TreeNodeSelectAction.Expand;
node.PopulateOnDemand = true;
this.Tvtree.Nodes.Add(node);

//添加本科模板
node = new TreeNode("本科", "20");
node.SelectAction = TreeNodeSelectAction.Expand;
node.PopulateOnDemand = true;
this.Tvtree.Nodes.Add(node);

//添加全院模板
node = new TreeNode("全院", "10");
node.SelectAction = TreeNodeSelectAction.Expand;
node.PopulateOnDemand = true;
this.Tvtree.Nodes.Add(node);
}

public void TreeShow(object sender, TreeNodeEventArgs e)
{
if (IsCallback)
if (e.Node.ChildNodes.Count == 0)
{
LoadChildNode(e.Node,int.Parse(e.Node.Value));
}
}

private void LoadChildNode(TreeNode node, Int32 id)
{
DataView dv = ds.Tables[0].DefaultView;
dv.RowFilter = string.Format(" sharekd = {0} ", id);
foreach (DataRowView drv in dv)
{
TreeNode nNew = new TreeNode();
nNew.Text = drv[GRPRCPPData.NAME_FIELD].ToString();
nNew.NavigateUrl = string.Format("AdvAcord.aspx?patid={0}&;amp;id={1}",
patid, des.Encrypt(drv[GRPRCPPData.ID_FIELD].ToString()));
node.ChildNodes.Add(nNew);
}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: