Private Property AccFunDataSet As DataSet Get Dim ds As DataSet If Session("AccFunctionsDataSet") Is Nothing Then Dim comm As New Common() Dim CodeMain As New MTRC.IRIS.DAL.codeMaintenance() Try ds = CodeMain.getAccFunctions("", Me.curLanguage) Dim dr As DataRow = ds.Tables(0).NewRow dr("AccessFunctionID") = "" ds.Tables(0).Rows.Add(dr) Session("AccFunctionsDataSet") = ds Catch ex As Exception comm.LogEvent(ex.Message, Diagnostics.EventLogEntryType.Error) Throw Finally CodeMain = Nothing comm = Nothing End Try Else ds = Session("AccFunctionsDataSet") End If Return ds End Get Set(ByVal value As DataSet) Session("AccFunctionsDataSet") = Nothing End Set End Property Private Function GetSubAccFunctions(ByVal ParentFunctionID As String, Optional ByVal IncludeEmptyRow As Boolean = False) As DataView Dim ds As DataSet = AccFunDataSet Dim filter As String = "AccessFunctionID='" + ParentFunctionID + "'" If IncludeEmptyRow Then filter += " Or AccessFunctionID=''" End If Dim dv As DataView = New DataView(ds.Tables(0), filter, "AccessFunctionID ASC", DataViewRowState.CurrentRows) Return dv End Function Private Sub ShowTree() tvwAccFunction.Nodes.Clear() Dim RootNode As New System.Web.UI.WebControls.TreeNode() RootNode.Text = "IRIS" RootNode.Value = "-" tvwAccFunction.Nodes.Add(RootNode) CreateChildTree(RootNode) RootNode.Select() End Sub Private Sub CreateChildTree(ByVal ParentNode As System.Web.UI.WebControls.TreeNode) ParentNode.Expanded = False Try Dim dv As DataView = GetSubAccFunctions(ParentNode.Value) Dim i As Integer For i = 0 To dv.Count - 1 Dim myTreeNode As New System.Web.UI.WebControls.TreeNode() myTreeNode.Text = dv(i)("AccessFunctionDesc") myTreeNode.Value = dv(i)("AccessSubFunctionID") ParentNode.ChildNodes.Add(myTreeNode) If dv(i)("HasChildren") Then CreateChildTree(myTreeNode) End If Next Catch ex As Exception Throw Finally End Try End Sub Protected Sub tvwAccFunction_SelectedNodeChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles tvwAccFunction.SelectedNodeChanged 'e.Node Dim node As TreeNode = tvwAccFunction.SelectedNode AccFunction = node.Value BindGrid(node.Value) Me.tvwAccFunction.CollapseAll() SelectedValuePath = node.ValuePath ExpandTreeNode(node) End Sub Private Sub ExpandTreeNode(ByVal valuePath As String) Dim node As TreeNode = tvwAccFunction.FindNode(valuePath) If Not node Is Nothing Then ExpandTreeNode(node) End If End Sub Private Sub ExpandTreeNode(ByVal node As TreeNode) Dim vp As String = node.ValuePath Dim pos As Integer = -1 pos = vp.IndexOf(tvwAccFunction.PathSeparator, pos + 1) While pos > 0 Dim nd As TreeNode = tvwAccFunction.FindNode(vp.Substring(0, pos)) nd.Expanded = True pos = vp.IndexOf(tvwAccFunction.PathSeparator, pos + 1) End While node.Expanded = True node.Selected = True End Sub
if (!Page.IsPostBack)
{
//InitTree(0, null);
Bing(0, null);
}private void Bing(int ParentID, TreeNode pNode)
{
DataSet ds = Product.Categorys_Get(0, 0, ParentID);
int num = ds.Tables[0].Rows.Count;
for (int i = 0; i < num;i++ )
{
TreeNode Tn = new TreeNode();
if (pNode == null)
{
Tn.Text = ds.Tables[0].Rows[i]["Title"].ToString() + "<font color='#003399'>·修改</font>";
Tn.Value = ds.Tables[0].Rows[i]["Id"].ToString();
TreeCategory.Nodes.Add(Tn);
Tn.Expanded = false;
Bing(Convert.ToInt32(ds.Tables[0].Rows[i]["Id"].ToString()), Tn); //再次递归
}
else
{
Tn.Text = ds.Tables[0].Rows[i]["Title"].ToString() + "<font color='#003399'>·修改</font>";
Tn.Value = ds.Tables[0].Rows[i]["Id"].ToString();
pNode.ChildNodes.Add(Tn);
Tn.Expanded = false;
Bing(Convert.ToInt32(ds.Tables[0].Rows[i]["Id"].ToString()), Tn); //再次递归
}
}
}
<asp:TreeView ID="TreeCategory" runat="server" ShowLines="True" CssClass="treelist"
ShowCheckBoxes="All" OnSelectedNodeChanged="TreeCategory_SelectedNodeChanged">
</asp:TreeView>
关键是刚开始的排序,一般用递归读取数据生成视图,或者用内连接和while实现
继续努力学习中..........
顶顶帖子,接分中........顶顶帖子,高手们也请多多赐教
http://topic.csdn.net/u/20110913/13/59f92d11-1fb0-4b7e-9c4a-e93d8f19c689.html
http://topic.csdn.net/u/20110611/12/3258c959-4f28-46b7-b5d6-46135d73036b.html
http://topic.csdn.net/u/20110722/14/89f7440b-c4d7-4c9a-a4bb-a503f5135db2.html
http://topic.csdn.net/u/20110729/10/a7bfaf06-0cf9-4580-8e91-d4e0b92066c6.html
http://topic.csdn.net/u/20110811/16/e56e7cc1-d8c9-40af-92e3-c24ca103d17d.html
http://topic.csdn.net/u/20110830/13/dfae4ca5-d2b9-4889-8a3c-6f7fb61936c9.html
http://topic.csdn.net/u/20110905/12/a1161adb-8e5d-491a-b302-c9722edf2dab.html
http://topic.csdn.net/u/20110913/16/2dbcc9db-8f71-40c5-901f-afae9026f7c2.html
http://topic.csdn.net/u/20110913/13/59f92d11-1fb0-4b7e-9c4a-e93d8f19c689.html
Get
Dim ds As DataSet If Session("AccFunctionsDataSet") Is Nothing Then
Dim comm As New Common()
Dim CodeMain As New MTRC.IRIS.DAL.codeMaintenance() Try
ds = CodeMain.getAccFunctions("", Me.curLanguage)
Dim dr As DataRow = ds.Tables(0).NewRow
dr("AccessFunctionID") = ""
ds.Tables(0).Rows.Add(dr) Session("AccFunctionsDataSet") = ds
Catch ex As Exception
comm.LogEvent(ex.Message, Diagnostics.EventLogEntryType.Error)
Throw
Finally
CodeMain = Nothing
comm = Nothing
End Try Else
ds = Session("AccFunctionsDataSet") End If Return ds
End Get
Set(ByVal value As DataSet)
Session("AccFunctionsDataSet") = Nothing
End Set
End Property
Private Function GetSubAccFunctions(ByVal ParentFunctionID As String, Optional ByVal IncludeEmptyRow As Boolean = False) As DataView Dim ds As DataSet = AccFunDataSet
Dim filter As String = "AccessFunctionID='" + ParentFunctionID + "'"
If IncludeEmptyRow Then
filter += " Or AccessFunctionID=''"
End If Dim dv As DataView = New DataView(ds.Tables(0), filter, "AccessFunctionID ASC", DataViewRowState.CurrentRows) Return dv End Function Private Sub ShowTree() tvwAccFunction.Nodes.Clear() Dim RootNode As New System.Web.UI.WebControls.TreeNode()
RootNode.Text = "IRIS"
RootNode.Value = "-" tvwAccFunction.Nodes.Add(RootNode)
CreateChildTree(RootNode) RootNode.Select() End Sub Private Sub CreateChildTree(ByVal ParentNode As System.Web.UI.WebControls.TreeNode) ParentNode.Expanded = False
Try
Dim dv As DataView = GetSubAccFunctions(ParentNode.Value)
Dim i As Integer
For i = 0 To dv.Count - 1
Dim myTreeNode As New System.Web.UI.WebControls.TreeNode()
myTreeNode.Text = dv(i)("AccessFunctionDesc")
myTreeNode.Value = dv(i)("AccessSubFunctionID") ParentNode.ChildNodes.Add(myTreeNode) If dv(i)("HasChildren") Then
CreateChildTree(myTreeNode)
End If Next
Catch ex As Exception
Throw
Finally End Try
End Sub Protected Sub tvwAccFunction_SelectedNodeChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles tvwAccFunction.SelectedNodeChanged
'e.Node
Dim node As TreeNode = tvwAccFunction.SelectedNode AccFunction = node.Value
BindGrid(node.Value) Me.tvwAccFunction.CollapseAll() SelectedValuePath = node.ValuePath ExpandTreeNode(node)
End Sub Private Sub ExpandTreeNode(ByVal valuePath As String)
Dim node As TreeNode = tvwAccFunction.FindNode(valuePath)
If Not node Is Nothing Then
ExpandTreeNode(node)
End If
End Sub Private Sub ExpandTreeNode(ByVal node As TreeNode)
Dim vp As String = node.ValuePath
Dim pos As Integer = -1
pos = vp.IndexOf(tvwAccFunction.PathSeparator, pos + 1)
While pos > 0
Dim nd As TreeNode = tvwAccFunction.FindNode(vp.Substring(0, pos))
nd.Expanded = True pos = vp.IndexOf(tvwAccFunction.PathSeparator, pos + 1)
End While node.Expanded = True
node.Selected = True
End Sub
JQuery zTree