参考一下:
http://xml.sz.luohuedu.net/xml/ShowDetail.asp?id=149E5DD7-3B32-461e-ACC6-51D1652E6746

解决方案 »

  1.   

    谢谢各位!
    to liuvb(★予人玫瑰 手有留香★) 
    http://xml.sz.luohuedu.net/xml/ShowDetail.asp?id=149E5DD7-3B32-461e-ACC6-51D1652E6746
    这个范例我看过了,但是它里面的子循环不能控制为固定的条数,如每个子循环为5条,如:
    http://www.standardio.org/images/155_1.gif
      

  2.   

    固定的条数:你可以设置  显示子datagrid数据的sql 语句  select top 5 * from table
      

  3.   

    谢谢senzz(森) !
    不过那样好像不可以,它只取出所有的子类别总数的5条,如果有4个大分类的话,应该选20条记录,但有可能这20全是某个大分类里的信息,其他分类有可能会不足5条子信息.
    而且这种方式只能有一个关键字可以关联,如果有两个关键字关联,就不知道怎么处理了.
      

  4.   

    你只要是设置“子datagrid" 允许分页,页大小为5行,就可以了
      

  5.   

    谢谢大伙给我出了这么多主意.让我收获很大,为了让和我有同样困惑的朋友做个参考,我巾出我刚调试成功的原代码,再次感谢!
    本代码主要想做成一个类似http://www.standardio.org/images/155_1.gif程序.
    有大分类及小分类,但小分类选取固定N条记录.里面的关联参数也可以传递多个.废话少讲,请看代码:MasterDetail.aspx:<%@ Page language="c#" Codebehind="MasterDetail.aspx.cs" AutoEventWireup="false" Inherits="MIS.MasterDetail" %>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
    <HTML>
    <HEAD>
    <title>MasterDetail</title>
    <meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
    <meta content="C#" name="CODE_LANGUAGE">
    <meta content="JavaScript" name="vs_defaultClientScript">
    <meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
    </HEAD>
    <body>
    <form id="Form1" method="post" runat="server">
    <asp:datagrid id="Par" runat="server" AutoGenerateColumns="False" Width="664px" Height="32px"
    HorizontalAlign="Center">
    <Columns>
    <asp:TemplateColumn HeaderText="大小分类范例">
    <ItemTemplate>
    <TABLE cellSpacing="0" cellPadding="0" width="100%" border="0">
    <TR>
    <TD bgColor="#99ccff">CustomerID:<%# DataBinder.Eval(Container.DataItem, "CustomerID") %></TD>
    </TR>
    <TR>
    <TD>
    <asp:DataGrid id=Child runat="server" Width="706px" DataSource='<%# getOrdersDataSource( (string)DataBinder.Eval(Container.DataItem, "CustomerID") ) %>'>
    </asp:DataGrid></TD>
    </TR>
    </TABLE>
    </ItemTemplate>
    </asp:TemplateColumn>
    </Columns>
    </asp:datagrid></form>
    </body>
    </HTML>MasterDetail.aspx.cs:using System;
    using System.Collections;
    using System.ComponentModel;
    using System.Data;
    using System.Data.SqlClient;
    using System.Configuration;
    using System.Drawing;
    using System.Web;
    using System.Web.SessionState;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.HtmlControls;namespace MIS
    {
    /// <summary>
    /// MasterDetail 的摘要说明。
    /// </summary>
    public class MasterDetail : System.Web.UI.Page
    {
    protected System.Web.UI.WebControls.DataGrid Par;
      private string conString = "server=localhost;database=Northwind;uid=sa;pwd=;"; private void Page_Load(object sender, System.EventArgs e)
    {
    if(!Page.IsPostBack)
    {
    BindData();

    } private void BindData()
    {
    string sqlStmt = "SELECT top 4  CustomerID FROM Customers";
    SqlConnection myConnection = new SqlConnection(conString);
    SqlCommand myCommand = new SqlCommand(sqlStmt, myConnection );
    myConnection.Open();
    Par.DataSource = myCommand.ExecuteReader(CommandBehavior.CloseConnection);
    Par.DataBind();
    } protected SqlDataReader getOrdersDataSource(string _customerID)

    string sqlStmt = "SELECT top 10  OrderID ,CustomerID ,EmployeeID, OrderDate FROM Orders where CustomerID='"+_customerID+"' ";
    SqlConnection myConnection = new SqlConnection(conString);
    SqlCommand myCommand = new SqlCommand(sqlStmt, myConnection );
    myConnection.Open();
    SqlDataReader result = myCommand.ExecuteReader(CommandBehavior.CloseConnection);
    return result;
    }  #region Web 窗体设计器生成的代码
    override protected void OnInit(EventArgs e)
    {
    //
    // CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
    //
    InitializeComponent();
    base.OnInit(e);
    }

    /// <summary>
    /// 设计器支持所需的方法 - 不要使用代码编辑器修改
    /// 此方法的内容。
    /// </summary>
    private void InitializeComponent()
    {    
    this.Load += new System.EventHandler(this.Page_Load); }
    #endregion
    }
    }