4个回答
展开全部
private void bindtreeview()
{
this.TreeView1.Nodes.Clear();
string strsql = "select * from title,detitle where title.title_id=detitle.title_id";
DataSet ds = DB.ds(strsql);
this.ViewState["DataSet_Tree"] = ds;
addtree(0, (TreeNode)null);
}
public void addtree(int ParentId, TreeNode pnode)
{
DataSet DataSet_Tree = (DataSet)this.ViewState["DataSet_Tree"];
DataView DataView_Tree = new DataView(DataSet_Tree.Tables[0]);
DataView_Tree.RowFilter = "title_id=" + ParentId;
foreach (DataRowView row in DataView_Tree)
{
TreeNode Node = new TreeNode();
if (pnode == null)
{
Node.Text = row["title_name"].ToString();
Node.Value = row["title_id"].ToString();
this.TreeView1.Nodes.Add(Node);
Node.Expanded = true;//展开当前节点
addtree(Int32.Parse(row["title_id"].ToString()), Node);
}
else
{
Node.Text = row["detitle_name"].ToString();
Node.Value=row["detitle_id"].ToString();
pnode.ChildNodes.Add(Node);
Node.Expanded = true;
addtree(Int32.Parse(row["detitle_id"].ToString()), Node);
}
}
{
this.TreeView1.Nodes.Clear();
string strsql = "select * from title,detitle where title.title_id=detitle.title_id";
DataSet ds = DB.ds(strsql);
this.ViewState["DataSet_Tree"] = ds;
addtree(0, (TreeNode)null);
}
public void addtree(int ParentId, TreeNode pnode)
{
DataSet DataSet_Tree = (DataSet)this.ViewState["DataSet_Tree"];
DataView DataView_Tree = new DataView(DataSet_Tree.Tables[0]);
DataView_Tree.RowFilter = "title_id=" + ParentId;
foreach (DataRowView row in DataView_Tree)
{
TreeNode Node = new TreeNode();
if (pnode == null)
{
Node.Text = row["title_name"].ToString();
Node.Value = row["title_id"].ToString();
this.TreeView1.Nodes.Add(Node);
Node.Expanded = true;//展开当前节点
addtree(Int32.Parse(row["title_id"].ToString()), Node);
}
else
{
Node.Text = row["detitle_name"].ToString();
Node.Value=row["detitle_id"].ToString();
pnode.ChildNodes.Add(Node);
Node.Expanded = true;
addtree(Int32.Parse(row["detitle_id"].ToString()), Node);
}
}
展开全部
public void CreateNode(String parentno, TreeNode parentnode, DataTable dt)
{
DataRow[] drs = dt.Select("ParentNo= " + parentno);
foreach (DataRow r in drs)
{
string nodeid = r["GroupNo"].ToString();
string text = r["GroupName"].ToString();
TreeNode node = new TreeNode();
node.Text = text;
node.Value = nodeid;
parentnode.ChildNodes.Add(node);
CreateNode(parentno,node,dt);
}
}
}
{
DataRow[] drs = dt.Select("ParentNo= " + parentno);
foreach (DataRow r in drs)
{
string nodeid = r["GroupNo"].ToString();
string text = r["GroupName"].ToString();
TreeNode node = new TreeNode();
node.Text = text;
node.Value = nodeid;
parentnode.ChildNodes.Add(node);
CreateNode(parentno,node,dt);
}
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
控件名.Nodes.add或者是控件名.ChlidNodes.add具体哪个忘记了
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
可以绑定数据源
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询