__在asp.net2.0下treeview怎么做的和csdn左边树一样啊?
要单击节点后,加载子节点数据,要无刷新。
怎么做啊,大家有用2.0做过没??
谢谢!~~
[解决办法]
SF!
[解决办法]
1.数据库结构你有了没。
2.asp.net ajax 你懂了没有。
[解决办法]
// MSDN
/*
下面的代码示例演示如何使用 PopulateNodesFromClient 属性启用 TreeView 控件中节点的客户端填充。请注意,启用了客户端节点填充后,会在客户端上自动填充节点,无需回发到服务器。
*/
<%@ Page Language= "C# " %>
<%@ Import Namespace= "System.Data " %>
<%@ Import Namespace= "System.Data.SqlClient " %>
<script runat= "server ">
void PopulateNode(Object sender, TreeNodeEventArgs e)
{
// Call the appropriate method to populate a node at a particular level.
switch(e.Node.Depth)
{
case 0:
// Populate the first-level nodes.
PopulateCategories(e.Node);
break;
case 1:
// Populate the second-level nodes.
PopulateProducts(e.Node);
break;
default:
// Do nothing.
break;
}
}
void PopulateCategories(TreeNode node)
{
// Query for the product categories. These are the values
// for the second-level nodes.
DataSet ResultSet = RunQuery( "Select CategoryID, CategoryName From Categories ");
// Create the second-level nodes.
if(ResultSet.Tables.Count > 0)
{
// Iterate through and create a new node for each row in the query results.
// Notice that the query results are stored in the table of the DataSet.
foreach (DataRow row in ResultSet.Tables[0].Rows)
{
// Create the new node. Notice that the CategoryId is stored in the Value property
// of the node. This will make querying for items in a specific category easier when
// the third-level nodes are created.
TreeNode newNode = new TreeNode();
newNode.Text = row[ "CategoryName "].ToString();
newNode.Value = row[ "CategoryID "].ToString();
// Set the PopulateOnDemand property to true so that the child nodes can be
// dynamically populated.
newNode.PopulateOnDemand = true;
// Set additional properties for the node.
newNode.SelectAction = TreeNodeSelectAction.Expand;
// Add the new node to the ChildNodes collection of the parent node.
node.ChildNodes.Add(newNode);
}
}
}
void PopulateProducts(TreeNode node)
{
// Query for the products of the current category. These are the values
// for the third-level nodes.
DataSet ResultSet = RunQuery( "Select ProductName From Products Where CategoryID= " + node.Value);
// Create the third-level nodes.
if(ResultSet.Tables.Count > 0)
{
// Iterate through and create a new node for each row in the query results.
// Notice that the query results are stored in the table of the DataSet.
foreach (DataRow row in ResultSet.Tables[0].Rows)
{
// Create the new node.
TreeNode NewNode = new TreeNode(row[ "ProductName "].ToString());
// Set the PopulateOnDemand property to false, because these are leaf nodes and
// do not need to be populated.
NewNode.PopulateOnDemand = false;
// Set additional properties for the node.
NewNode.SelectAction = TreeNodeSelectAction.None;
// Add the new node to the ChildNodes collection of the parent node.
node.ChildNodes.Add(NewNode);
}
}
}
DataSet RunQuery(String QueryString)
{
// Declare the connection string. This example uses Microsoft SQL Server
// and connects to the Northwind sample database.
String ConnectionString = "server=localhost;database=NorthWind;Integrated Security=SSPI ";
SqlConnection DBConnection = new SqlConnection(ConnectionString);
SqlDataAdapter DBAdapter;
DataSet ResultsDataSet = new DataSet();
try
{
// Run the query and create a DataSet.
DBAdapter = new SqlDataAdapter(QueryString, DBConnection);
DBAdapter.Fill(ResultsDataSet);
// Close the database connection.
DBConnection.Close();
}
catch(Exception ex)
{
// Close the database connection if it is still open.
if(DBConnection.State == ConnectionState.Open)
{
DBConnection.Close();
}
Message.Text = "Unable to connect to the database. ";
}
return ResultsDataSet;
}
</script>
<html>
<body>
<form runat= "server ">
<h3> TreeView PopulateNodesFromClient Example </h3>
<asp:TreeView id= "LinksTreeView "
Font-Name= "Arial "
ForeColor= "Blue "
EnableClientScript= "true "
PopulateNodesFromClient= "true "
OnTreeNodePopulate= "PopulateNode "
runat= "server ">
<Nodes>
<asp:TreeNode Text= "Inventory "
SelectAction= "Expand "
PopulateOnDemand= "true "/>
</Nodes>
</asp:TreeView>
<br> <br>
<asp:Label id= "Message " runat= "server "/>
</form>
</body>
</html>
[解决办法]
csdn不是用.NET的Tree控件的,用了一个梅花雪的控件。楼主网上搜一下
[解决办法]
和1.1的没什么区别吧
[解决办法]
要這么麻煩嗎?可以很簡單,直接寫,用CSS控制!
[解决办法]
mark!
[解决办法]
梅花雪
别人是老大阿,全部js实现的吧...
[解决办法]
若用treeview绝对不可能跟csdn的一样!
[解决办法]
see:
http://www.meizz.com/
[解决办法]
用IeWebcontrol的话参看 Http://www.aspxboy.com/code/
[解决办法]
LZ是否是从数据库加载的节点