悬赏园豆:10
[已关闭问题]
<P>目前的一个项目,在加载TreeView时性能很慢,大家有什么方法改进,请指教!</P>
<P>以下是相关的代码:</P>
<P> #region 模块树数据的加载<BR> /// <summary><BR> /// 模块树数据的加载<BR> /// </summary><BR> /// <param name="languageType"></param><BR> /// <param name="Nds"></param><BR> /// <param name="ParentId"></param><BR> private void BindModuleDetail(string languageType, TreeNodeCollection Nds, string ParentId, int LoginUserId, int RoleId)<BR> {<BR> DataView dvModuleDetails = new DataView();<BR> TreeNode tmpNd;</P>
<P> string strRID;<BR> dvModuleDetails.Table = dt;<BR> dvModuleDetails.RowFilter = " parentCode='" + ParentId + "'";</P>
<P> foreach (DataRowView dvModuleDetail in dvModuleDetails)<BR> {<BR> tmpNd = new TreeNode();<BR> strRID = dvModuleDetail["ModuleCode"].ToString();<BR> tmpNd.Value = dvModuleDetail["ModuleCode"].ToString();</P>
<P> switch (languageType.ToLower())<BR> {<BR> case "chn":<BR> tmpNd.Text = dvModuleDetail["ModuleNameChn"].ToString();<BR> break;<BR> case "eng":<BR> tmpNd.Text = dvModuleDetail["ModuleNameEng"].ToString();<BR> break;<BR> case "big5":<BR> tmpNd.Text = dvModuleDetail["ModuleNameBig5"].ToString();<BR> break;<BR> }</P>
<P> Nds.Add(tmpNd);</P>
<P> BindModuleFunctionTemplate(languageType, tmpNd.ChildNodes, LoginUserId, RoleId, tmpNd.Value);<BR> BindModuleDetail(languageType, tmpNd.ChildNodes, strRID, LoginUserId, RoleId);<BR> }</P>
<P> }<BR> #endregion</P>
<P> #region 模块树节点功能的加载<BR> /// <summary><BR> /// 模块树节点功能的加载<BR> /// </summary><BR> /// <param name="languageType"></param><BR> /// <param name="Nds"></param><BR> /// <param name="RoleId"></param><BR> /// <param name="ModuleCode"></param><BR> public void BindModuleFunctionTemplate(string languageType, TreeNodeCollection Nds, int UserId, int RoleId, string ModuleCode)<BR> {<BR> DataView dvModuleFunctions = new DataView();<BR> TreeNode tmpNd;</P>
<P> string strRID;<BR> DataSet ds = mftb.GetModuleFunctionByModuleCode(ModuleCode);<BR> dvModuleFunctions.Table = ds.Tables[0];</P>
<P> foreach (DataRowView dvModuleFunction in dvModuleFunctions)<BR> {<BR> tmpNd = new TreeNode();<BR> strRID = dvModuleFunction["ModuleCode"].ToString();<BR> tmpNd.Value = dvModuleFunction["ModuleCode"].ToString();<BR> tmpNd.ToolTip = dvModuleFunction["FunctionItem"].ToString();</P>
<P> if (!(dvModuleFunction["FunctionItem"].ToString() == string.Empty))<BR> {<BR> switch (languageType.ToLower())<BR> {<BR> case "chn":<BR> tmpNd.Text = dvModuleFunction["FunctionItemDesChn"].ToString();<BR> break;<BR> case "eng":<BR> tmpNd.Text = dvModuleFunction["FunctionItemDesEng"].ToString();<BR> break;<BR> case "big5":<BR> tmpNd.Text = dvModuleFunction["FunctionItemDesBig5"].ToString();<BR> break;<BR> }</P>
<P> Nds.Add(tmpNd);<BR> DataSet dsTemp = new DataSet();<BR> dsTemp = rmb.GetRoleModulesByModuleCodeAndFunctionItem(tmpNd.Value, dvModuleFunction["FunctionItem"].ToString());<BR> if (dsTemp.Tables[0].Rows.Count > 0)<BR> {<BR> if (RoleId == int.Parse(dsTemp.Tables[0].Rows[0]["RoleId"].ToString()))<BR> {<BR> tmpNd.Checked = true;<BR> }<BR> }<BR> else<BR> {<BR> Nds.Remove(tmpNd);<BR> }<BR> }</P>
<P> }<BR> }<BR> #endregion</P>