|
// '递归遍历自建目录树=============================================================================
private void ShowDir(string sZml,string sIndex)
{
System.Data.SqlClient.SqlConnection sqlCon=new System.Data.SqlClient.SqlConnection(connectionString);
string sqlStr="select * from mltable where mlzml=N'"+ sZml +"'";
System.Data.SqlClient.SqlDataAdapter sqlAda=new System.Data.SqlClient.SqlDataAdapter(sqlStr,sqlCon);
System.Data.DataTable Dt=new DataTable();
sqlAda.Fill(Dt);
Microsoft.Web.UI.WebControls.TreeNode Node1;
string sIndex0;
string sIndex2;
int theId;
int sIndex1=0;//记录树的最后一位值
foreach(System.Data.DataRow DtDataRow in Dt.Rows)
{
theId=Convert.ToInt32(DtDataRow["mlid"]);
Node1=new Microsoft.Web.UI.WebControls.TreeNode();
Node1.Text=DtDataRow["mlmc"].ToString();
Node1.ImageUrl="images/trees/folder.gif";
Node1.ExpandedImageUrl="images/trees/folderopen.gif";
Node1.Expanded=false;
Node1.NavigateUrl="Admin_Tree_Show.ASPx?theid=" + theId +"&sIndex="+ sIndex+"."+sIndex1.ToString();
Node1.ID="";
Node1.Target="main";
if(sIndex=="")
{
sIndex2=TreeView1.Nodes.IndexOf(Node1).ToString();
sIndex0=sIndex2;
}
else
{
Microsoft.Web.UI.WebControls.TreeNode pNode=TreeView1.GetNodeFromIndex(sIndex);
pNode.Nodes.Add(Node1);
sIndex2=pNode.Nodes.IndexOf(Node1).ToString();
sIndex0=sIndex + "." + sIndex2;
sIndex1++;//记录当前树下叶子的个数,即当前叶子的号
}
ShowDir(DtDataRow["mlid"].ToString(),sIndex0);
}
sqlCon.Close();
}
AspNet技术:asp.net 无限分类第1/3页,转载需保留来源!
郑重声明:本文版权归原作者所有,转载文章仅为传播更多信息之目的,如作者信息标记有误,请第一时间联系我们修改或删除,多谢。