首页 新闻 会员 周边 捐助

treeview 数据显示不出来

0
[已解决问题] 解决于 2011-03-14 10:28

后台代码

View Code
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);
}
}

}

前台代码:

View Code
<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>
我是一根葱的主页 我是一根葱 | 初学一级 | 园豆:5
提问于:2011-03-09 11:44
< >
分享
最佳答案
0

跟踪调试一下。这看着貌似也没有什么大问题。看看你的datatable中是否有数据啊

邢少 | 专家六级 |园豆:10926 | 2011-03-09 14:52
谢谢,我已经解决了!
我是一根葱 | 园豆:5 (初学一级) | 2011-03-14 10:28

@我是一根葱: 咋解决的

陨风沐雨 | 园豆:200 (初学一级) | 2020-08-19 09:16
其他回答(1)
0

AddTree的if和else有区别吗

期待是绝望 | 园豆:112 (初学一级) | 2011-03-09 14:50
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册