get the two tables into a DataSet, create a relationship them, and use GetChildRows, see306154 HOW TO: Display Hierarchical Data by Using Nested Repeater Controls
and Visual C# .NET
http://support.microsoft.com/default.aspx?scid=kb;en-us;306154

解决方案 »

  1.   

    你的回复和给的页子我看了一下,意思是在DataSet中存放这两张表,并用relationship进行关联,然后用两个嵌套Repeater进行绑定?
      

  2.   

    这样实现有些问题:
    1、我这要实现"Top 6"的功能,怎样在RowFilter中设定筛选条件呢。
    2、每次都Fill全部相关记录,如果相关记录够多的话,岂不很占资源?
      

  3.   

    1. no, you have to do it manually, or use SQL to do the top 62. use paging, and only select the data for the current page
      

  4.   

    可是我这有两个相关字段,一为classid,表示文章的大类,另一为nclassid,表示相关大类下的小类,填充的两个DataTable,一张为指定大类下的小类信息,另一张为指定大类下的所有小类之文章,所以好像实现不了你所说的"top 6"或者分页技术,因为小类的nclassid不能确定。相关代码如下:
    DataSet Content=new DataSet();
    SqlDataAdapter myDA1=new SqlDataAdapter("select top 5 NclassID,Nclass,orders from ANclass where classID="+id+" and lock=1 order by orders",conn);
    myDA1.Fill(Content,"BClass1");
    SqlDataAdapter myDA2=new SqlDataAdapter("select articleid,title,dateandtime,nclassid from article where classid="+id+" and state='yes' order by articleid desc",conn);
    myDA2.Fill(Content,"NewArts1");
    Content.Relations.Add("nclassid",
    Content.Tables["BClass1"].Columns["nclassid"],
    Content.Tables["NewArts1"].Columns["nclassid"]);
    Content.Tables["BClass1"].DefaultView.RowFilter="orders<3";
    BClass1.DataSource=Content.Tables["BClass1"].DefaultView;
    BClass1.DataBind();
    Content.Tables["BClass1"].DefaultView.RowFilter="orders>2";
    BClass2.DataSource=Content.Tables["BClass1"].DefaultView;
    BClass2.DataBind();
      

  5.   

    select * from y文章的大类tableselect * from 文章的小类 t1 where nclassid in (select top 6 nclassid from 文章的小类 t2 where t1.classid = t2.classid order by article_date desc)
      

  6.   

    你可能领会错我的意思,主要是我讲得不清楚。
    其实大类的classid是由查询字符串得到的,而现在我想显示的是由查询字符串得到的大类下的所有小类的前6篇文章。(三张表,一张是存放大类信息的,这张表该页用不着检索,因为是由查询字符串得到的大类ID,第二张是存放小类信息的,这两张表的相关字段是classid,第三张表是存放文章信息的,和前两张表关联的字段是大类ID和小类ID)
    网址:http://www.jzxx.net/student/对于您的热心帮助表示感谢!