asp.net web application (in VB)treeview控件怎么通过代码和数据库绑定?可不可以不通过xml文件?直接在.aspx里写函数来建树?
解决方案 »
- 一个asp转asp.net的菜鸟关于asp.net前台开发的求教
- ASP关闭一个页面并让另一个页面重新加载数据
- 求助,网页的高度和宽度
- vs.net2003打包安装出错:未将对象引用设置到对象的实例,怎么回事?
- SQL菜鸟级的问题
- 急求
- 点了button 面页上的数据就丢了咋办??
- 【新手初到】今天刚到一个公司上班,经理给了个sql语句查询的问题,要考验我 急!如果3天解决不出来就走人~~~~~~~~~~~~
- asp.net1.1能用IO类 吗?
- 如何让TEXTBOX输完数后,自动跳到另一个TEXTBOX,让它获得焦点?如何判断输完数?
- 重庆 ASP.NET C# 开发
- asp.net[C#] 为何删除不了sql server上的数据呢??? 困扰了两天了!
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
SqlConnection myConnection;
SqlCommand myCommand;
myConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["Personal"].ConnectionString);
myCommand = new SqlCommand();
myCommand.Connection = myConnection;
myCommand.CommandType = CommandType.Text;
myCommand.CommandText = "SELECT [SoftFirstClassID], [SoftFirstClassName] FROM [SoftFirstClass]";
myConnection.Open();
SqlDataReader sr = myCommand.ExecuteReader();
try
{
while (sr.Read())
{
TreeNode tn1 = new TreeNode();
tn1.Text = sr.GetString(1);
tn1.Selected = false;
tn1.SelectAction = TreeNodeSelectAction.None;
TreeView1.Nodes.Add(tn1); int firstClassID = sr.GetInt32(0);
SqlConnection secondConnection;
SqlCommand secondCommand;
secondConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["Personal"].ConnectionString);
secondCommand = new SqlCommand();
secondCommand.Connection = secondConnection;
secondCommand.CommandType = CommandType.Text;
secondCommand.CommandText = "SELECT [SoftSecondClassID], [SoftSecondClassName] FROM [SoftSecondClass] WHERE ([SoftFirstClassID] = @SoftFirstClassID)";
secondCommand.Parameters.AddWithValue("@SoftFirstClassID", firstClassID);
secondConnection.Open();
SqlDataReader sr2 = secondCommand.ExecuteReader();
try
{
while (sr2.Read())
{
TreeNode tn2 = new TreeNode();
tn2.Text = sr2.GetString(1);
tn2.Value = (sr2.GetInt32(0)).ToString();
//TreeView1.Nodes.AddAt(i, tn2);
tn1.ChildNodes.Add(tn2);
}
}
finally
{
sr2.Close();
secondConnection.Close();
}
}
}
finally
{
sr.Close();
myConnection.Close();
}
} }
两级树代码
1.http://www.meizz.com/Web/Web.asp2.
微软网站
http://www.microsoft.com/china/msdn/archives/library/workshop/webcontrols/overview/treeview.asp3.
引用:
http://community.csdn.net/Expert/topic/4196/4196863.xml?temp=9.365261E-03
http://community.csdn.net/Expert/topic/3169/3169028.xml?temp=.8414118
我找了一个用递归方法写的动态生成树的函数(in vb)
不过因为对DataRowView一些属性不大清楚,有的地方不知要怎么相应地改动
请高手帮忙看看
Public Sub AddTree(ByVal ParentID As Integer, ByVal pNode As TreeNode)
Dim DataView_Tree As DataView
DataSet_Tree = Me.ViewState("DataSet_Tree")
DataView_Tree = New DataView(DataSet_Tree.Tables(0))
DataView_Tree.RowFilter = "*******" '.ToString() & (ParentID.ToString())
Dim Row As DataRowView For Each Row In DataView_Tree
Dim node = New TreeNode
node.NavigateUrl = "List.aspx?Item_ID=" + Row("****").ToString()
Dim aa As New TreeNode
If ParentID = 0 Then '添加根节点
node.Text = Row("*****").ToString()
TreeView_Tree.Nodes.Add(node)
node.Expanded = True
AddTree(Int32.Parse(Row(***)), node) Else
node.Text = Row("****").ToString()
pNode.Nodes.Add(node)
node.Expanded = True
AddTree(Int32.Parse(Row("****").ToString()), node) End If Next End Sub
数据库中有表topnode, midnode, lownode
topnode 中有字段:topid, toptext
midnode: midid, topid, midtext
lownode: lowid, midid, lowtext结果是要实现从数据库中读取后分层显示,toptext,midtext,lowtext的内容分别在第一、二、三层