谁有05下,asp.net好用的treeview的例子 谁有05下,asp.net好用的treeview的例子谢谢! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 http://www.cnblogs.com/zm235/archive/2007/05/10/595019.html 楼上的例子不错,非常适合初学者,如果不用到数据库,也可以直接在aspx文件里写:<asp:TreeView ID="TreeView1" runat="server" Height="265px" ImageSet="Faq" ShowLines="True" ExpandDepth="1" Target="fmain"> <ParentNodeStyle Font-Bold="False" /> <HoverNodeStyle Font-Underline="True" ForeColor="Purple" /> <SelectedNodeStyle Font-Underline="True" HorizontalPadding="0px" VerticalPadding="0px" /> <Nodes> <asp:TreeNode Text="一级" Value="1" Expanded="true" SelectAction="Expand" > <asp:TreeNode Text="二级一" Value="2" NavigateUrl="http://www.baidu.com" Target="fmain"></asp:TreeNode> <asp:TreeNode Text="二级二" NavigateUrl="http://www.163.com" Target="fmain"></asp:TreeNode> </asp:TreeNode> </Nodes> <NodeStyle Font-Names="Tahoma" Font-Size="8pt" ForeColor="DarkBlue" HorizontalPadding="5px" NodeSpacing="0px" VerticalPadding="0px" /></asp:TreeView> <asp:TreeView ID="TreeView1" Runat="server"> <Nodes> <asp:TreeNode Value="Parent1" Expanded="True" Text="1"> <asp:TreeNode Value="Child1A" Text="A" /> <asp:TreeNode Value="Child1B" Text="B" /> </asp:TreeNode> <asp:TreeNode Value="Parent2" Text="2"> </asp:TreeNode> <asp:TreeNode Value="Parent3" Expanded="True" Text="3"> <asp:TreeNode Value="Child3A" Text="A"> </asp:TreeNode> </asp:TreeNode> </Nodes></asp:TreeView> 上网搜搜,再就是看msdn 或者看看天轰穿的视频教程 就自带TREEVIEW,不过加脚本很麻烦,缺陷 就用vs2005自带的树控件,下面是动态绑定代码: TreeNode RootNode = new TreeNode();//先添加个根节点 RootNode.Value = this.TextBox1.Text; RootNode.Text = this.TextBox2.Text; TreeView1.Nodes.Add(RootNode); DataSet ds2 = GridBind(SSHDHAO);//下面开始循环加子节点,你可以嵌套循环来分层 if (ds2.Tables[0].Rows.Count > 0) { for (int i = 0; i < ds2.Tables[0].Rows.Count; i++) { TreeNode Node = new TreeNode(); string aaa = ""; Node.Value = ds2.Tables[0].Rows[i]["字段1"].ToString(); Node.Text = ds2.Tables[0].Rows[i]["字段2"].ToString(); RootNode.ChildNodes.Add(Node); } } Index.html文件:<html><frameset cols="150,*"> <frame name="treeview" src="Default.aspx"> <frame name="main"></frameset></html>aspx文件:Default.aspx:<body> <form id="form1" runat="server"> <div> <asp:TreeView ID="TreeView1" runat="server" Target="main"> </asp:TreeView> </div> </form></body>Default.aspx.cs文件:public partial class _Default : System.Web.UI.Page { private OleDbConnection conn; private OleDbDataAdapter da; private DataSet ds; private string sql; protected void Page_Load(object sender, EventArgs e) { if ( !this.IsPostBack ) { string connstr = System.Configuration.ConfigurationManager.ConnectionStrings [ "connectionString" ].ConnectionString; conn = new OleDbConnection ( connstr ); sql = "SELECT * FROM [TreeViewTable]"; da = new OleDbDataAdapter ( sql, conn ); ds = new DataSet (); da.Fill ( ds, "tree" ); InitTree ( this.TreeView1.Nodes, "000" ); } } private void InitTree ( TreeNodeCollection nodes, string parentId ) { DataRow [] rows = this.ds.Tables [ "tree" ].Select ( "ParentId='" + parentId + "'" ); foreach ( DataRow dr in rows ) { TreeNode tmpNode = new TreeNode (); tmpNode.Text = dr [ "NodeName" ].ToString (); tmpNode.NavigateUrl = dr [ "Url" ].ToString (); nodes.Add ( tmpNode ); string id = dr [ "NodeId" ].ToString (); InitTree ( tmpNode.ChildNodes, id );//递归循环添加节点 } }}Web.config文件:<connectionStrings> <add name="connectionString" connectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\data.mdb"/></connectionStrings>TreeViewTable表记录如下:NodeId ParentId NodeName Url001 000 ... ...002 001 ... ...003 001 ... ...004 002 ... ...005 002 ... ...006 003 ... ...007 003 ... ... 急!!!读取数句库中Studen表,exam表,study表。加条件登记学时! CSDN生成的静态页面,有些回复登陆后才能看到,是如何做到的? 关于websocket 最大连接数 100分甩了 不支持关键字 DATA source 大家都会遇到的问题~ 请高人指点如何取得小数点后两位 问一下,有谁对动网7.1的cookies欺骗成功过? 数据库存储图片网页显示时如何与其他网页元素共存(一个页面实现)?望高手指教,感兴趣的帮顶! 未将对象引用设置到对象的实例。 谁能帮我? asp.net中用什么控件可以在粘贴时支持word文件复制格式 如何 获取 所画 直线 的 坐标集合
<ParentNodeStyle Font-Bold="False" />
<HoverNodeStyle Font-Underline="True" ForeColor="Purple" />
<SelectedNodeStyle Font-Underline="True" HorizontalPadding="0px" VerticalPadding="0px" />
<Nodes>
<asp:TreeNode Text="一级" Value="1" Expanded="true" SelectAction="Expand" >
<asp:TreeNode Text="二级一" Value="2" NavigateUrl="http://www.baidu.com" Target="fmain"></asp:TreeNode>
<asp:TreeNode Text="二级二" NavigateUrl="http://www.163.com" Target="fmain"></asp:TreeNode>
</asp:TreeNode>
</Nodes>
<NodeStyle Font-Names="Tahoma" Font-Size="8pt" ForeColor="DarkBlue" HorizontalPadding="5px"
NodeSpacing="0px" VerticalPadding="0px" />
</asp:TreeView>
<Nodes>
<asp:TreeNode Value="Parent1" Expanded="True" Text="1">
<asp:TreeNode Value="Child1A" Text="A" />
<asp:TreeNode Value="Child1B" Text="B" />
</asp:TreeNode>
<asp:TreeNode Value="Parent2" Text="2">
</asp:TreeNode>
<asp:TreeNode Value="Parent3" Expanded="True" Text="3">
<asp:TreeNode Value="Child3A" Text="A">
</asp:TreeNode>
</asp:TreeNode>
</Nodes>
</asp:TreeView>
TreeNode RootNode = new TreeNode();//先添加个根节点
RootNode.Value = this.TextBox1.Text;
RootNode.Text = this.TextBox2.Text;
TreeView1.Nodes.Add(RootNode);
DataSet ds2 = GridBind(SSHDHAO);//下面开始循环加子节点,你可以嵌套循环来分层
if (ds2.Tables[0].Rows.Count > 0)
{
for (int i = 0; i < ds2.Tables[0].Rows.Count; i++)
{
TreeNode Node = new TreeNode();
string aaa = "";
Node.Value = ds2.Tables[0].Rows[i]["字段1"].ToString();
Node.Text = ds2.Tables[0].Rows[i]["字段2"].ToString();
RootNode.ChildNodes.Add(Node);
} }
<html>
<frameset cols="150,*">
<frame name="treeview" src="Default.aspx">
<frame name="main">
</frameset>
</html>aspx文件:
Default.aspx:
<body>
<form id="form1" runat="server">
<div>
<asp:TreeView ID="TreeView1" runat="server" Target="main">
</asp:TreeView>
</div>
</form>
</body>
Default.aspx.cs文件:
public partial class _Default : System.Web.UI.Page
{
private OleDbConnection conn;
private OleDbDataAdapter da;
private DataSet ds;
private string sql; protected void Page_Load(object sender, EventArgs e)
{
if ( !this.IsPostBack )
{
string connstr = System.Configuration.ConfigurationManager.ConnectionStrings [ "connectionString" ].ConnectionString;
conn = new OleDbConnection ( connstr );
sql = "SELECT * FROM [TreeViewTable]";
da = new OleDbDataAdapter ( sql, conn );
ds = new DataSet ();
da.Fill ( ds, "tree" );
InitTree ( this.TreeView1.Nodes, "000" );
}
} private void InitTree ( TreeNodeCollection nodes, string parentId )
{
DataRow [] rows = this.ds.Tables [ "tree" ].Select ( "ParentId='" + parentId + "'" );
foreach ( DataRow dr in rows )
{
TreeNode tmpNode = new TreeNode ();
tmpNode.Text = dr [ "NodeName" ].ToString ();
tmpNode.NavigateUrl = dr [ "Url" ].ToString ();
nodes.Add ( tmpNode );
string id = dr [ "NodeId" ].ToString ();
InitTree ( tmpNode.ChildNodes, id );//递归循环添加节点
}
}
}
Web.config文件:
<connectionStrings>
<add name="connectionString" connectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\data.mdb"/>
</connectionStrings>TreeViewTable表记录如下:
NodeId ParentId NodeName Url
001 000 ... ...
002 001 ... ...
003 001 ... ...
004 002 ... ...
005 002 ... ...
006 003 ... ...
007 003 ... ...