asp.net 无限分类第1/3页
时间:2021-07-01 10:21:17
帮助过:34人阅读
1、递归函数
// '递归遍历自建目录树=============================================================================
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();
}
123下一页阅读全文