TreeView树型结构显示
数据库有三个表,既一级栏目,二级栏目,三级栏目
读取三个表时在树型结构的文字显示前加单选按钮,并可操作
//创建顶级目录树
private void SortMotherNodes(TreeNodeCollection Nds)
{
TreeNode MotherNd;
MotherNd = new TreeNode();
MotherNd.ID = "0";
MotherNd.Text = "网站栏目";
MotherNd.Target = "Child";
MotherNd.NavigateUrl = "SortAdmin_Child_Index.aspx";
Nds.Add(MotherNd);
this.Sort1stList(MotherNd.Nodes);
}
//绑定一级栏目
private void Sort1stList(TreeNodeCollection Nds)
{
string sort = "1";
TreeNode tmpNd;
dv = new DataView();
dv.Table = this.DataSetSort1stList().Tables["vtable"];
foreach(DataRowView dr in dv)
{
tmpNd = new TreeNode();
tmpNd.ID = dr["Sort1stID"].ToString();
tmpNd.Text = dr["Sort1stName"].ToString();
tmpNd.Target="Child";
tmpNd.NavigateUrl = "SortAdmin_Child.aspx?SortID="+tmpNd.ID+"&Sort="+sort;
Nds.Add(tmpNd);
this.Sort2ndList(tmpNd.Nodes,tmpNd.ID);
}
}
//绑定二级栏目
private void Sort2ndList(TreeNodeCollection Nds,string ID_1st)
{
string sort = "2";
TreeNode tmpNd;
dv = new DataView();
dv.Table = this.DataSetSort2ndList(ID_1st).Tables["vtable"];
dv.RowFilter = "Sort1stID="+ID_1st;
foreach(DataRowView dr in dv)
{
tmpNd = new TreeNode();
tmpNd.ID = dr["Sort2ndID"].ToString();
tmpNd.Text = dr["Sort2ndName"].ToString();
tmpNd.Target="Child";
tmpNd.NavigateUrl = "SortAdmin_Child.aspx?SortID="+tmpNd.ID+"&Sort="+sort;
Nds.Add(tmpNd);
Sort3rdList(tmpNd.Nodes,tmpNd.ID);
}
}
//绑定三级栏目
private void Sort3rdList(TreeNodeCollection Nds,string ID_2nd)
{
string sort = "3";
TreeNode tmpNd;
dv = new DataView();
dv.Table = DataSetSort3rdList(ID_2nd).Tables["vtable"];
dv.RowFilter = "Sort2ndID="+ID_2nd;
foreach(DataRowView dr in dv)
{
tmpNd = new TreeNode();
tmpNd.ID = dr["Sort3rdID"].ToString();
tmpNd.Text = dr["Sort3rdName"].ToString();
tmpNd.Target="Child";
tmpNd.NavigateUrl = "SortAdmin_Child.aspx?SortID="+tmpNd.ID+"&Sort="+sort;
Nds.Add(tmpNd);
}
}