asp.net treeview的使用

[复制链接]
查看11 | 回复2 | 2010-2-23 13:37:27 | 显示全部楼层 |阅读模式
private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
{
string s = "";
s = e.Node.Name.ToString();}
回复

使用道具 举报

千问 | 2010-2-23 13:37:27 | 显示全部楼层
直接写查询语句这个应该会写把,然后调用递归方法protected void Page_Load(object sender, EventArgs e)
{
LoadTree(TreeView1, "1");//根节点id
}
///
/// 检索root
///
/// 建立根
/// 根节点名称
public void LoadTree(TreeView tv, string strParentId)
{
tv.Nodes.Clear();
SqlCommand cmd = sct.GetCommandStr("select 党组织编码,党组织名称 from T_Party where [id] =" + strParentId);//在这里更换你表的查询语句
DataTable dt = sct.GetDataSet(cmd, "T_Party");
string str = "", strE = "";
if (dt.Rows.Count > 0)
{
str = dt.Rows[0]["党组织编码"].ToString();
strE = dt.Rows[0]["党组织名称"].ToString();
}
if (str != "")
{
TreeNode node = new TreeNode();
node.Text = strE;
node.Value = strParentId;
node.NavigateUrl = node.NavigateUrl = "Default.aspx?id=" + node.Text + "";
//给节点添加客户端脚本
//node.Value = node.Value + node.Parent.Text + "\"onclick=\"javascript:LoadPage('" + node.Value + "');";
tv.Nodes.Add(node);
SqlCommand cmd1 = sct.GetCommandStr("select * from T_Party where 党组织编码 like '" + str + "%'");//在这里更换你表的查询语句
DataTable dt1 = sct.GetDataSet(cmd1, "T_Party1");
CreateNode(node, dt1);
}
}
///
/// 递归子节点
///
/// 树杈
/// 对应该树杈的table
private static void CreateNode(TreeNode node, DataTable dt)
{
DataRow[] dr = dt.Select("parentID=" + node.Value);
if (dr.Length > 0)
{
foreach (DataRow d in dr)
{
TreeNode tNode = new TreeNode();
tNode.Text = d["党组织名称"].ToString();
tNode.Value = d["id"].ToString();
tNode.NavigateUrl = "Default.aspx?id=" + tNode.Text + "";
//给节点添加客户端脚本
//tNode.Value = tNode.Value + tNode.Value + "\"onclick=\"javascript:LoadPage('" + tNode.Value + "');";
node.ChildNodes.Add(tNode);
tNode.Expanded = false;
CreateNode(tNode, dt);
}
}
}
回复

使用道具 举报

千问 | 2010-2-23 13:37:27 | 显示全部楼层
这里有详细的例子:http://hi.baidu.com/laicaly/blog/item/4a87daf25190dfc87831aa19.html
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行