我想实现 这样的一个效果[分类] 此分类下的相关数据 此分类下的相关数据 此分类下的相关数据 [更多]例子:[下载软件] 脱兔下载 网络蚂蚁 网际快车 [更多]那数据库的表 和 字段 应该怎么设置好?我现在是这样但 总是不能实现上面那个效果数据中 2个表,一个表储存分类
字段有 ID [自动增量] ,分类名称[文本类型]另一个表储存数据
假设有 字段 ID,分类ID,数据
我用asp.net 应该怎么写能 实现上面的效果?

解决方案 »

  1.   

    用嵌套的数据绑定控件,比如 DataList 里面套一个 Repeater.里面的数据源用 select top n 语句来取。
      

  2.   

    DataGrid嵌套DataGrid
    public void BindGrid()
    {
    DB op = new DB();
    SqlConnection cn = op.createConn2;
    DataSet ds = new DataSet();
    SqlDataAdapter da = new SqlDataAdapter("select * from news_class",cn);
    da.Fill(ds);
    this.DataGrid1.DataSource = ds;
    this.DataGrid1.DataBind();
    for(int i=0;i<this.DataGrid1.Items.Count;i++)
    {
    Label l = (Label)this.DataGrid1.Items[i].FindControl("lblBigID");
    DataGrid dg = (DataGrid)this.DataGrid1.Items[i].FindControl("DataGrid2");
    SqlDataAdapter da2 = new SqlDataAdapter("select * from news where classid="+l.Text,cn);
    DataSet ds2 = new DataSet();
    da2.Fill(ds2);
    dg.DataSource = ds2;
    dg.DataBind();
    }
    }
      

  3.   

    DataGrid比DataList控件好用,
    很多攻能都有,不要自己做。表码,个人觉得应该做两个表,一个类型的。一个内容的。   create table TypeTable
        (TypeID int identity(1,1) primary key, TypeName varchar(20))   create table 内容表
        (内容ID int primary key,TypeID int foreign key References TypeTable(TypeName).........下面是其它的列啊。 )
      

  4.   

    谢谢 artak(甜葡萄)请问下 NeilChen123 ,能列举个具体的代码吗?我想各种方法都试一下.哪个比较灵活和简洁实用.早上起来结贴给分哦