日期:2014-05-20  浏览次数:20825 次

TREEVIEW绑定之后不能显示
以下是代码,为什么可以运行,但是在网页之中显示不出来 

一个显示页面Default.aspx 


<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %> 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml" > 
<head id="Head1" runat="server"> 
  <title>无标题页 </title> 
</head> 
<body> 
  <form id="form1" runat="server"> 
  <div> 
   
  <asp:TreeView ID="tvMenu" runat="server" ImageSet="Faq" ShowLines="True" ExpandDepth="0" Target="middle" > 
  <ParentNodeStyle Font-Bold="False" /> 
  <HoverNodeStyle Font-Underline="True" ForeColor="Purple" /> 
  <SelectedNodeStyle Font-Underline="True" HorizontalPadding="0px" VerticalPadding="0px" /> 
  <NodeStyle Font-Names="Tahoma" Font-Size="8pt" ForeColor="DarkBlue" HorizontalPadding="5px" 
  NodeSpacing="0px" VerticalPadding="0px" /> 
  </asp:TreeView> 
  
  </div> 
  </form> 
</body> 
</html> 


一个代码隐藏页Default.aspx.cs 


using System; 
using System.Data; 
using System.Configuration; 
using System.Web; 
using System.Web.Security; 
using System.Web.UI; 
using System.Web.UI.WebControls; 
using System.Web.UI.WebControls.WebParts; 
using System.Web.UI.HtmlControls; 
using System.Data.SqlClient; 

public partial class _Default : System.Web.UI.Page 

  SqlConnection Conn = new SqlConnection("server=20090207-0309;database=checkthree;uid=sa;pwd=1111"); 
  
  DataSet ds; 
  protected void Page_Load(object sender, EventArgs e) 
  { 
  Conn.Open(); 
  this.createDataSet(); 
  Conn.Close(); 
  this.InitTree(tvMenu.Nodes, "0"); 
  } 
  private DataSet createDataSet() 
  { 
  ds = new DataSet(); 
  string sqlStr = "select * from Tree "; 
  SqlDataAdapter cmdSelect = new SqlDataAdapter(sqlStr, Conn); 
  cmdSelect.Fill(ds, "Tree"); 
  return ds; 
  } 
  protected void InitTree(TreeNodeCollection Nds, string parentId)//用递归方法动态生成节点 
  { 
  DataView dv = new DataView(); 
  TreeNode tmpNode; 
  dv.Table = ds.Tables["Tree"]; 
  dv.RowFilter = "pat_id=" + "'" + parentId + "'"; 
  foreach (DataRowView drv in dv) 
  { 
  tmpNode = new TreeNode(); 
  tmpNode.Value = drv["node_id"].ToString(); 
  tmpNode.Text = drv["naode_name"].ToString(); 
  tmpNode.NavigateUrl = drv["url"].ToString(); 
  Nds.Add(tmpNode);