在DataGrid如何把一对多关系的数据显示出来 http://dotnet.aspx.cc/ShowDetail.aspx?id=149E5DD7-3B32-461e-ACC6-51D1652E6746 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 你的這種應該是SQL語句的問題了 这一个是你想要的:<%@ Page Language="C#" %><%@ Import Namespace="System.Data" %><%@ Import Namespace="System.Data.SqlClient" %><script runat=server>void Page_Load(Object sender , EventArgs e) { DataSet dstNorthwind; SqlConnection conNorthwind; SqlDataAdapter dadNorthwind; // Grab the Categories and Products table dstNorthwind = new DataSet(); conNorthwind = new SqlConnection( @"Server=localhost;Integrated Security=SSPI;Database=Northwind" ); dadNorthwind = new SqlDataAdapter( "Select * From Categories", conNorthwind ); conNorthwind.Open(); dadNorthwind.Fill( dstNorthwind, "Categories" ); dadNorthwind.SelectCommand = new SqlCommand( "Select * From Products", conNorthwind ); dadNorthwind.Fill( dstNorthwind, "Products" ); conNorthwind.Close(); // Add Parent/Child Relationship dstNorthwind.Relations.Add( "Categories_Products", dstNorthwind.Tables["Categories"].Columns["CategoryID"], dstNorthwind.Tables["Products"].Columns["CategoryID"] ); // Display each Category and Child Products foreach (DataRow drowParent in dstNorthwind.Tables["Categories"].Rows) { lblOutput.Text = "<h3>" + drowParent["CategoryName"] + "</h3>"; foreach (DataRow drowChild in drowParent.GetChildRows( "Categories_Products" )) { lblOutput.Text = "<li>" + drowChild["ProductName"]; } }}</Script><html><head><title>DataRelation.aspx</title></head><body><asp:Label ID="lblOutput" Runat="Server" /></body></html> datarelation 是处理datatable之间的关系 http://www.denisbauer.com/ASPNETControls/HierarGrid.aspx闭馆说的是另一策,hdhai说的不对 好像很麻烦,不如多用几个DataGrid. C# ini文件如何读取一个section中的key 外加一读取问题 水晶报表本机运行ok,用ip访问时拒绝访问 是什么原因 WPF中怎么禁用右键菜单? 用C#怎样实现屏幕截图 [散分]大家贴出C#操作各种数据库的helper类,供使用时查看 怎样实俐化 对象数组 有C#高手吗? 怎样在即时窗口中用命令让一个页面等候20秒? AsyncCallback 到底是事件还是方法?怎么理解 有关委托或事件之 界面之间传值 如何替换 .exe .dll 文件中的资源? 请教一个调用窗体的问题
这一个是你想要的:<%@ Page Language="C#" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %><script runat=server>void Page_Load(Object sender , EventArgs e)
{
DataSet dstNorthwind;
SqlConnection conNorthwind;
SqlDataAdapter dadNorthwind; // Grab the Categories and Products table
dstNorthwind = new DataSet();
conNorthwind = new SqlConnection( @"Server=localhost;Integrated Security=SSPI;Database=Northwind" );
dadNorthwind = new SqlDataAdapter( "Select * From Categories", conNorthwind );
conNorthwind.Open();
dadNorthwind.Fill( dstNorthwind, "Categories" );
dadNorthwind.SelectCommand = new SqlCommand( "Select * From Products", conNorthwind );
dadNorthwind.Fill( dstNorthwind, "Products" );
conNorthwind.Close(); // Add Parent/Child Relationship
dstNorthwind.Relations.Add( "Categories_Products", dstNorthwind.Tables["Categories"].Columns["CategoryID"], dstNorthwind.Tables["Products"].Columns["CategoryID"] ); // Display each Category and Child Products
foreach (DataRow drowParent in dstNorthwind.Tables["Categories"].Rows)
{
lblOutput.Text = "<h3>" + drowParent["CategoryName"] + "</h3>";
foreach (DataRow drowChild in drowParent.GetChildRows( "Categories_Products" ))
{
lblOutput.Text = "<li>" + drowChild["ProductName"];
}
}
}
</Script><html>
<head><title>DataRelation.aspx</title></head>
<body><asp:Label
ID="lblOutput"
Runat="Server" /></body>
</html>
闭馆说的是另一策,hdhai说的不对