0
我已经添加了一个treeview到我的系统。我可以设法显示树视图的内容。但是输出与我预期的不一样。这里我添加了输出的图像。请看看它。为什么Treeview不显示层次结构?
ASPX代码
<asp:TreeView ID="TreeView1" 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="10px"></NodeStyle>
<ParentNodeStyle Font-Bold="False" />
<SelectedNodeStyle BackColor="#B5B5B5" Font-Underline="False" HorizontalPadding="0px"
VerticalPadding="2px" />
</asp:TreeView>
C#代码
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
dt=getDataObj.treeSketch();
PopulateTreeView(dt, 0, null);
}
}
private void PopulateTreeView(DataTable dsParent, int parentId, TreeNode treeNode)
{
foreach (DataRow row in dsParent.Rows)
{
TreeNode child = new TreeNode
{
Text = row["FUNCTION_NAME"].ToString(),
Value = row["FUNCTION_CODE"].ToString()
};
if (parentId == 0)
{
TreeView1.Nodes.Add(child);
dt = getDataObj.loadTree(child);
PopulateTreeView(dt, int.Parse(child.Value), child);
}
else
{
treeNode.ChildNodes.Add(child);
}
}
}
在这里用大写字母节点AR e主节点和其他子节点。为什么它不像树视图?如何使它工作?
查询
public DataTable loadTree(TreeNode child)
{
string strQuery = @"select FUNCTION_CODE,USER_TYPE from [WEB_FUNCTIONACCESS]
where FUNCTION_CODE = '"+ child +"' ";
return SqlHelper.ExecuteDataset(strConnStringAppeal, CommandType.Text, strQuery).Tables[0];
}
其实这个代码我在互联网上找到。所以即使我还没有一个适当的想法呢 – Mike
你可以在本地调试代码并逐行执行吗? – woodykiddy
你认为我应该怎么做才能做到这一点? – Mike