|
5#
楼主 |
发表于 2013-1-7 12:46:38
|
只看该作者
guns_ken 发表于 2013-1-7 01:43
我每加载一个节点都会设置一次Expanded的,你这个问题我以前也遇到过,第二级不展开 ... - <Toolbars>
- <x:Toolbar ID="Toolbar1" runat="server">
- <Items>
- <x:Button ID="btnExpandAll" runat="server" Text="展开" OnClick="btnExpandAll_Click">
- </x:Button>
- <x:Button ID="btnCollapseAll" runat="server" Text="折叠" OnClick="btnCollapseAll_Click">
- </x:Button>
- </Items>
- </x:Toolbar>
- </Toolbars>
- <Items>
- <x:Tree ID="treeNav" runat="server" AutoScroll="true" EnableArrows="true"
- Title="文件夹管理器" EnableLargeHeader="True" onnodecommand="treeNav_NodeCommand" ShowHeader="False">
- </x:Tree>
- </Items>
-
复制代码- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.Web;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- using System.Data;
- using ExtAspNet;
- using Jazz.DBUtility;
- namespace WebJazz.FileSys
- {
- public partial class _default : iBasePage
- {
- protected void Page_Load(object sender, EventArgs e)
- {
- if (!IsPostBack)
- {
-
- LoadTree();
-
- treeNav.ExpandAllNodes();
- InitCtrl();
- }
- }
- protected void btnExpandAll_Click(object sender, EventArgs e)
- {
- treeNav.ExpandAllNodes();
- }
- protected void btnCollapseAll_Click(object sender, EventArgs e)
- {
- treeNav.CollapseAllNodes();
- }
- protected void treeNav_NodeCommand(object sender, TreeCommandEventArgs e)
- {
- gridFile.PageIndex = 0;
- gridFile.FindColumn("FolderName").Hidden = true;
- ttbSearch.Text = null;
- BindGrid();
- }
- # region 生成无限级树
- public void LoadTree()
- {
- Jazz.BLL.FileSys.Folder bll = new Jazz.BLL.FileSys.Folder();
- string str = string.Format("SELECT DISTINCT dbo.zz_FileSys_Folder.* FROM dbo.zz_FileSys_Folder WHERE (zz_FileSys_Folder.ParentId IS NULL) ORDER BY FolderSortIndex");
- DataTable dt = DbHelperSQL.Query(str).Tables["ds"];
-
- foreach (DataRow row in dt.Rows)
- {
- ExtAspNet.TreeNode node = new ExtAspNet.TreeNode();
- node.NodeID = row["FolderId"].ToString();
- node.Text = row["FolderName"].ToString();
- string sqlstr = string.Format("ParentId='{0}'", row["FolderId"].ToString());
- int child = bll.GetList(sqlstr).Tables["ds"].Rows.Count;
- if (child == 0)
- {
- //
- }
- else
- {
- node.Expanded = true;
- node.SingleClickExpand = true;
- LoadChild(row["FolderId"].ToString(), node);
- }
- treeNav.Nodes.Add(node);
-
- }
- }
- public void LoadChild(string parentid, ExtAspNet.TreeNode treeNode)
- {
- Jazz.BLL.FileSys.Folder bll = new Jazz.BLL.FileSys.Folder();
- string str = string.Format("SELECT DISTINCT dbo.zz_FileSys_Folder.* FROM dbo.zz_FileSys_Folder WHERE (zz_FileSys_Folder.ParentId='{0}') ORDER BY zz_FileSys_Folder.FolderSortIndex", parentid);
-
- DataTable dt = DbHelperSQL.Query(str).Tables["ds"];
-
- if (dt.Rows.Count > 0)
- {
- foreach (DataRow row in dt.Rows)
- {
- ExtAspNet.TreeNode node = new ExtAspNet.TreeNode();
-
- node.NodeID = row["FolderId"].ToString();
- node.Text = row["FolderName"].ToString();
- node.EnablePostBack = true;
- string sqlstr = string.Format("ParentId='{0}'", row["FolderId"].ToString());
- int child = bll.GetList(sqlstr).Tables["ds"].Rows.Count;
- if (child == 0)
- {
- //
- }
- else
- {
- node.Expanded = true;
- node.SingleClickExpand = true;
- LoadChild(row["FolderId"].ToString(), node);
- }
- treeNode.Nodes.Add(node);
- }
- }
- }
- #endregion
- #region BindGrid
- private DataTable GridSource()
- {
- Jazz.BLL.FileSys.File bll = new Jazz.BLL.FileSys.File();
- string str;
- string searchText = ttbSearch.Text.Trim();
- if (!String.IsNullOrEmpty(searchText))
- {
- if (chkSubFolder.Checked)
- str = string.Format("SELECT DISTINCT dbo.view_FolderFile.* FROM dbo.view_FolderFile WHERE ((view_FolderFile.FolderId='{0}' OR CHARINDEX('{0},',vFolderFullPath)>0) AND CHARINDEX('{1}',FileName)>0)", treeNav.SelectedNodeID, searchText);
- else
- str = string.Format("SELECT DISTINCT dbo.view_FolderFile.* FROM dbo.view_FolderFile WHERE (view_FolderFile.FolderId='{0}' AND CHARINDEX('{1}',FileName)>0)", treeNav.SelectedNodeID, searchText);
- }
- else
- str = string.Format("SELECT DISTINCT dbo.view_FolderFile.* FROM dbo.view_FolderFile WHERE (view_FolderFile.FolderId='{0}')", treeNav.SelectedNodeID);
- DataTable dt = DbHelperSQL.Query(str).Tables["ds"];
- return dt;
- }
- private void BindGrid()
- {
- DataTable dt= GridSource();
- gridFile.SelectedRowIndexArray = null;
- gridFile.DataSource = dt;
- gridFile.DataBind();
- }
- protected void gridFile_PageIndexChange(object sender, GridPageEventArgs e)
- {
- gridFile.PageIndex = e.NewPageIndex;
- }
- protected void gridFile_RowCommand(object sender, GridCommandEventArgs e)
- {
- object[] values = gridFile.DataKeys[e.RowIndex];
- int id = Convert.ToInt32(values[0]);
- string name = Convert.ToString(values[1]);
- if (e.CommandName == "Delete")
- {
- }
- }
- protected void gridFile_RowDoubleClick(object sender, GridRowClickEventArgs e)
- {
- }
- protected void gridFile_Sort(object sender, GridSortEventArgs e)
- {
- DataTable dt = GridSource();
- DataView dv = dt.DefaultView;
- dv.Sort = string.Format("{0} {1}", e.SortField, e.SortDirection);
- gridFile.DataSource = dv;
- gridFile.DataBind();
- }
- #endregion
- protected void btnUpload_Click(object sender, EventArgs e)
- {
- //winFrame.GetShowReference("fileUpload.aspx", "新增");
- }
- protected void WinFrame_Close(object sender, WindowCloseEventArgs e)
- {
- BindGrid();
- }
- private void NodeExpand()
- {
- //treeNav.SelectedNodeID = "3";
- //treeNav.SelectedNode.Text = "项目文件";
- //指定展开某个节点,并为选中状态
- BindGrid();
- }
- private void InitCtrl()
- {
- NodeExpand();
- btnUpload.OnClientClick = winFrame.GetShowReference("fileUpload.aspx", "新增");
- }
- #region Events
- protected void ttbSearch_Trigger1Click(object sender, EventArgs e)
- {
- ttbSearch.Text = String.Empty;
- ttbSearch.ShowTrigger1 = false;
- BindGrid();
- }
- protected void ttbSearch_Trigger2Click(object sender, EventArgs e)
- {
- ttbSearch.ShowTrigger1 = true;
- gridFile.FindColumn("FolderName").Hidden=false;
- BindGrid();
- }
-
- #endregion
- }
- }
复制代码
|
|