TreeView数据读取出错!全读到根节点了``请大虾帮下忙
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
if(!this.Page.IsPostBack)
{
string connectString = "data source=.;initial catalog=apple;user id=sa;password=197861 ";
SqlConnection conn = new SqlConnection(connectString);
conn.Open();
SqlDataAdapter da = new SqlDataAdapter( "select * from tree ",conn);
DataSet ds = new DataSet();
da.Fill(ds);
this.ViewState[ "ds "] = ds;
this.addNode( "0 ",(TreeNode)null);
//this.TreeView1.Attributes.Add( "oncheck ", "tree_oncheck(this) ");
}
}
private void addNode(string ParentID,TreeNode pNode)
{
DataSet ds = (DataSet)this.ViewState[ "ds "];
DataView dvTree = new DataView(ds.Tables[0]);
dvTree.RowFilter = "[parentid] = " "+ParentID+ " " ";
foreach(DataRowView drv in dvTree)
{
TreeNode node = new TreeNode();
if(pNode == null)
{
node.Text = drv[ "title "].ToString();
this.TreeView1.Nodes.Add(node);
node.Expanded = true;
node.NavigateUrl = drv[ "url "].ToString();
node.Target = "right ";
node.CheckBox = true;
this.addNode(drv[ "id "].ToString(),node);
}
else
{
node.Text = drv[ "title "].ToString();
pNode.Nodes.Add(node);
node.Expanded = true;
node.NavigateUrl = drv[ "url "].ToString();
node.Target = "right ";
node.CheckBox = true;
node.NodeData = drv[ "id "].ToString();
this.addNode(drv[ "id "].ToString(),node);
}
}
}
怎么都是读到根节点
[解决办法]
up
[解决办法]
用递归求解