表News        字段 News_id,News_Title,News_Typeid
表News_Type      字段 Type_Id,Type_Name请问如何将News 中的记录按News_Type的分类分别显示出来 

解决方案 »

  1.   

    select a.News_id,a.News_Title,b.Type_Name from News a inner join News_Type b on a.News_Typeid=b.Type_Id group by a.News_Typeid
      

  2.   

    采用datagrid嵌套的方式显示出来,如
    public void BindGrid()
    {
    DB op = new DB();//这里是数据连接的,自己看
    SqlConnection cn = op.createConn2;
    DataSet ds = new DataSet();
    SqlDataAdapter da = new SqlDataAdapter("select * from shop_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 shop_books where classid="+l.Text,cn);
    DataSet ds2 = new DataSet();
    da2.Fill(ds2);
    dg.DataSource = ds2;
    dg.DataBind();
    }
    }