后台代码
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
SqlConnection sqlconncgtiontree = new SqlConnection();
sqlconncgtiontree.ConnectionString = SqlCommon.ConnectionStringLocalTransaction.ToString();
sqlconncgtiontree.Open();
SqlDataAdapter sqlda = new SqlDataAdapter("select ColumnsID,ColumnsName,ParentID from Columns", sqlconncgtiontree);
DataSet DataSet_Tree = new DataSet();
sqlda.Fill(DataSet_Tree);
this.ViewState["DataSet_Tree"] = DataSet_Tree;
AddTree(0, (TreeNode)null);
sqlconncgtiontree.Close();
}
}
protected void btnSave_Click(object sender, EventArgs e)
{
UserAdmin_System uas = new UserAdmin_System();
uas.Add_UserAdmin(this.tbUserName.Text,BLL.SMJY.Common.MD5.Lower32(this.tbUserPsd.Text),this.tbTureName.Text,this.TextBox1.Text,1);
BasicPage.FinalMessage("成功保存", "close.htm", 0);
}
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 = "[ParentID]=" + ParentID;
foreach (DataRowView Row in DataView_Tree)
{
TreeNode Node = new TreeNode();
if (pNode == null)
{
Node.Text = Row["ColumnsName"].ToString();
ColumnsTree.Nodes.Add(Node);
Node.Expanded = true;
AddTree(Int32.Parse(Row["ColumnsID"].ToString()), Node);
}
else
{
Node.Text = Row["ColumnsName"].ToString();
//pNode.ChildNodes.Add(Node);
ColumnsTree.Nodes.Add(Node);
Node.Expanded = true;
AddTree(Int32.Parse(Row["ColumnsID"].ToString()), Node);
}
}
}
前台代码:
<asp:TreeView ID="ColumnsTree" runat ="server" ImageSet="XPFileExplorer"
NodeIndent="15">
<HoverNodeStyle Font-Underline="True" ForeColor="#6666AA" />
<NodeStyle Font-Names="Tahoma" Font-Size="8pt" ForeColor="Black"
HorizontalPadding="2px" NodeSpacing="0px" VerticalPadding="2px" />
<ParentNodeStyle Font-Bold="False" />
<SelectedNodeStyle BackColor="#B5B5B5" Font-Underline="False"
HorizontalPadding="0px" VerticalPadding="0px" />
</asp:TreeView>
跟踪调试一下。这看着貌似也没有什么大问题。看看你的datatable中是否有数据啊
@我是一根葱: 咋解决的
AddTree的if和else有区别吗