参考一下:
http://xml.sz.luohuedu.net/xml/ShowDetail.asp?id=149E5DD7-3B32-461e-ACC6-51D1652E6746
http://xml.sz.luohuedu.net/xml/ShowDetail.asp?id=149E5DD7-3B32-461e-ACC6-51D1652E6746
解决方案 »
- repeater控件套用repeater,套用repeater里的数据显示
- VS2008水晶报表如何将SQL语句作为参数传到报表
- 问个数据库链接问题!(在线等待,加急~~~~)
- 局部刷新页面,左边是产品,右边是产品明细
- 怎么在页面中对aspnetdb中的用户进行管理,比如删除和修改,
- 请问如何在ASP.NET程序中用DSN来链接SQL SERVER
- 如何在一个asp.net虚拟空间上放多个asp.net网站?
- 插不进去,有错吗
- 关于texbox输入的值更新数据库的问题
- 求助:网页中的多语言功能是用哪些方法解决的??
- [求助]继承datagrid问题
- 关于企业及模板项目中的VC#简单分布式应用的问题。
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
不过那样好像不可以,它只取出所有的子类别总数的5条,如果有4个大分类的话,应该选20条记录,但有可能这20全是某个大分类里的信息,其他分类有可能会不足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
}
}