大类别表:bigsort字段 bigsortid int
     bigsortname narchar200---------------------------------------小类别: samllsort字段 smallsortid int
     smallsortname nvarchar200
     bigsortid int
如何分层显示呢:
按下面这样,显示大类,然后遍历大类下的小类,然后下条大类,然后下条大类的小类--------------------------------大类一
  小类11111
  小类22222
大类二
  小类11111
  小类22222
大类三
  小类11111
  小类22222

解决方案 »

  1.   

    你将两个表建立一个视图,然后根据视图中的字段去绑定这个treeview
      

  2.   

    你可以只用一张表的,3个字段:ID,ParentID,NameCREATE TABLE [dbo].[tblSort](
    [SortID] [int] NOT NULL,
    [ParentID] [int] NULL,
    [SortName] [varchar](50) COLLATE Chinese_PRC_CI_AS NULL,
     CONSTRAINT [PK_tblSort] PRIMARY KEY CLUSTERED 
    (
    [SortID] ASC
    )WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
    ) ON [PRIMARY]
    SELECT 
    CONVERT(VARCHAR,ParentID) AS ParentID
    ,convert(varchar,SortID) as KeyID
    ,SortName as Name
    ,dense_rank() over(order by ParentID)  as [Level]
    FROM tblSort A 
      

  3.   

    简单写了下create table bigsort(bigsortid int,bigsortname varchar(20))
    insert into bigsort
    select 1,'大类一' union all
    select 2,'大类二' union all
    select 3,'大类三'create table samllsort(smallsortid int,smallsortname varchar(20),bigsortid int)
    insert into samllsort
    select 1,'小类11',1 union all
    select 2,'小类12',1 union all
    select 3,'小类21',2 union all
    select 4,'小类22',2 union all
    select 5,'小类31',3 union all
    select 6,'小类32',3 
        protected void Page_Load(object sender, EventArgs e)
        {
            DataTable dtBig = GetBig();
            DataTable dtSmall = GetSmall();
            foreach (DataRow row in dtBig.Rows)
            {
                TreeNode node = new TreeNode(row["bigsortname"].ToString(), row["bigsortid"].ToString());
                foreach (DataRow r in dtSmall.Select("bigsortid=" + row["bigsortid"]))
                {
                    node.ChildNodes.Add(new TreeNode(r["smallsortname"].ToString(), r["smallsortid"].ToString()));
                }
                TreeView1.Nodes.Add(node);
            }
        }
        public DataTable GetBig()
        {
            DataTable dt = new DataTable();
            using (SqlConnection conn = new SqlConnection())
            {
                conn.ConnectionString = ConfigurationManager.ConnectionStrings["Connection"].ConnectionString;
                conn.Open();
                SqlDataAdapter da = new SqlDataAdapter("select bigsortid,bigsortname from bigsort", conn);
                da.Fill(dt);
            }
            return dt;
        }
        public DataTable GetSmall()
        {
            DataTable dt = new DataTable();
            using (SqlConnection conn = new SqlConnection())
            {
                conn.ConnectionString = ConfigurationManager.ConnectionStrings["Connection"].ConnectionString;
                conn.Open();
                SqlDataAdapter da = new SqlDataAdapter("select smallsortid,smallsortname,bigsortid from samllsort", conn);
                da.Fill(dt);
            }
            return dt;
        }
      

  4.   

    晕死  视图就是一句查询语句 select * from 视图名称 .以前不是select * from 表名么!