DataList嵌套DataList(使用DataRelation实现 纯代码)
2008-10-09 09:22
435 查看
aspx
view plaincopy to clipboardprint?
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="DataListNesting.aspx.cs" Inherits="DataListNesting" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>DataListNesting</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:DataList ID="DataList1" runat="server">
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Eval("OrderID") %>'></asp:Label>
<asp:Label ID="Label2" runat="server" Text='<%# Eval("CustomerID") %>'></asp:Label>
<asp:DataList ID="DataList2" runat="server" DataSource='<%# (Container.DataItem as System.Data.DataRowView).Row.GetChildRows("myRelation") %>'>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# (Container.DataItem as System.Data.DataRow)["ProductID"] %>'></asp:Label>
<asp:Label ID="Label2" runat="server" Text='<%# (Container.DataItem as System.Data.DataRow)["UnitPrice"] %>'></asp:Label>
<asp:Label ID="Label3" runat="server" Text='<%# (Container.DataItem as System.Data.DataRow)["Quantity"] %>'></asp:Label>
</ItemTemplate>
</asp:DataList>
</ItemTemplate>
</asp:DataList>
</div>
</form>
</body>
</html>
view plaincopy to clipboardprint?
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
public partial class DataListNesting : System.Web.UI.Page
{
private void BindList()
{
SqlConnection cn = new SqlConnection(@"server=./sqlexpress;uid=sa;pwd=;database=northwind;");
SqlDataAdapter da = new SqlDataAdapter("select OrderID, CustomerID from Orders; select OrderID, ProductID, UnitPrice, Quantity from [Order Details]", cn);
DataSet ds = new DataSet();
cn.Open();
da.Fill(ds);
cn.Close();
ds.Tables[0].TableName = "Orders";
ds.Tables[1].TableName = "OrderDetails";
DataRelation ordersToOrderDetails = ds.Relations.Add("myRelation", ds.Tables["Orders"].Columns["OrderID"], ds.Tables["OrderDetails"].Columns["OrderID"]);
DataList1.DataSource = ds.Tables["Orders"];
DataList1.DataBind();
}
private void Page_Load(object sender, System.EventArgs e)
{
if (!IsPostBack)
{
BindList();
}
}
//protected void DataList1_ItemDataBound(object sender, DataListItemEventArgs e)
//{
// DataList DataList2;
// if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
// {
// DataList2 = e.Item.FindControl("DataList2") as DataList;
// DataList2.DataSource = ((DataRowView)(e.Item.DataItem)).Row.GetChildRows("myRelation");
// DataList2.DataBind();
// }
//}
}
view plaincopy to clipboardprint?
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="DataListNesting.aspx.cs" Inherits="DataListNesting" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>DataListNesting</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:DataList ID="DataList1" runat="server">
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Eval("OrderID") %>'></asp:Label>
<asp:Label ID="Label2" runat="server" Text='<%# Eval("CustomerID") %>'></asp:Label>
<asp:DataList ID="DataList2" runat="server" DataSource='<%# (Container.DataItem as System.Data.DataRowView).Row.GetChildRows("myRelation") %>'>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# (Container.DataItem as System.Data.DataRow)["ProductID"] %>'></asp:Label>
<asp:Label ID="Label2" runat="server" Text='<%# (Container.DataItem as System.Data.DataRow)["UnitPrice"] %>'></asp:Label>
<asp:Label ID="Label3" runat="server" Text='<%# (Container.DataItem as System.Data.DataRow)["Quantity"] %>'></asp:Label>
</ItemTemplate>
</asp:DataList>
</ItemTemplate>
</asp:DataList>
</div>
</form>
</body>
</html>
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="DataListNesting.aspx.cs" Inherits="DataListNesting" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server"> <title>DataListNesting</title> </head> <body> <form id="form1" runat="server"> <div> <asp:DataList ID="DataList1" runat="server"> <ItemTemplate> <asp:Label ID="Label1" runat="server" Text='<%# Eval("OrderID") %>'></asp:Label> <asp:Label ID="Label2" runat="server" Text='<%# Eval("CustomerID") %>'></asp:Label> <asp:DataList ID="DataList2" runat="server" DataSource='<%# (Container.DataItem as System.Data.DataRowView).Row.GetChildRows("myRelation") %>'> <ItemTemplate> <asp:Label ID="Label1" runat="server" Text='<%# (Container.DataItem as System.Data.DataRow)["ProductID"] %>'></asp:Label> <asp:Label ID="Label2" runat="server" Text='<%# (Container.DataItem as System.Data.DataRow)["UnitPrice"] %>'></asp:Label> <asp:Label ID="Label3" runat="server" Text='<%# (Container.DataItem as System.Data.DataRow)["Quantity"] %>'></asp:Label> </ItemTemplate> </asp:DataList> </ItemTemplate> </asp:DataList> </div> </form> </body> </html>aspx.cs
view plaincopy to clipboardprint?
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
public partial class DataListNesting : System.Web.UI.Page
{
private void BindList()
{
SqlConnection cn = new SqlConnection(@"server=./sqlexpress;uid=sa;pwd=;database=northwind;");
SqlDataAdapter da = new SqlDataAdapter("select OrderID, CustomerID from Orders; select OrderID, ProductID, UnitPrice, Quantity from [Order Details]", cn);
DataSet ds = new DataSet();
cn.Open();
da.Fill(ds);
cn.Close();
ds.Tables[0].TableName = "Orders";
ds.Tables[1].TableName = "OrderDetails";
DataRelation ordersToOrderDetails = ds.Relations.Add("myRelation", ds.Tables["Orders"].Columns["OrderID"], ds.Tables["OrderDetails"].Columns["OrderID"]);
DataList1.DataSource = ds.Tables["Orders"];
DataList1.DataBind();
}
private void Page_Load(object sender, System.EventArgs e)
{
if (!IsPostBack)
{
BindList();
}
}
//protected void DataList1_ItemDataBound(object sender, DataListItemEventArgs e)
//{
// DataList DataList2;
// if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
// {
// DataList2 = e.Item.FindControl("DataList2") as DataList;
// DataList2.DataSource = ((DataRowView)(e.Item.DataItem)).Row.GetChildRows("myRelation");
// DataList2.DataBind();
// }
//}
}
using System; using System.Data; using System.Configuration; using System.Collections; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; using System.Data.SqlClient; public partial class DataListNesting : System.Web.UI.Page { private void BindList() { SqlConnection cn = new SqlConnection(@"server=./sqlexpress;uid=sa;pwd=;database=northwind;"); SqlDataAdapter da = new SqlDataAdapter("select OrderID, CustomerID from Orders; select OrderID, ProductID, UnitPrice, Quantity from [Order Details]", cn); DataSet ds = new DataSet(); cn.Open(); da.Fill(ds); cn.Close(); ds.Tables[0].TableName = "Orders"; ds.Tables[1].TableName = "OrderDetails"; DataRelation ordersToOrderDetails = ds.Relations.Add("myRelation", ds.Tables["Orders"].Columns["OrderID"], ds.Tables["OrderDetails"].Columns["OrderID"]); DataList1.DataSource = ds.Tables["Orders"]; DataList1.DataBind(); } private void Page_Load(object sender, System.EventArgs e) { if (!IsPostBack) { BindList(); } } //protected void DataList1_ItemDataBound(object sender, DataListItemEventArgs e) //{ // DataList DataList2; // if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) // { // DataList2 = e.Item.FindControl("DataList2") as DataList; // DataList2.DataSource = ((DataRowView)(e.Item.DataItem)).Row.GetChildRows("myRelation"); // DataList2.DataBind(); // } //} }
相关文章推荐
- DataList嵌套DataList(3. 使用DataRelation实现 纯代码)
- DataList嵌套DataList(页面绑定后台代码使用ItemDataBound事件实现 纯代码)
- DataList嵌套DataList(2. 页面绑定后台代码使用ItemDataBound事件实现 纯代码)
- DataList嵌套DataList(页面绑定后台代码使用ItemDataBound事件实现 纯代码)
- DataList嵌套DataList(使用SqlDataSource实现)
- DataList嵌套DataList(4. 使用SqlDataSource实现)
- android 如何使用代码实现嵌套布局
- DataRelation 实现父子表 父子级 Repeater的嵌套使用
- DataList嵌套DataList 子DataList访问父DataList数据(1. 页面绑定后台代码实现 纯代码)
- fastjson-1.2.21 使用实例,复杂嵌套Java对象转json对象,复杂嵌套json对象转对应Java对象的代码实现
- Datalist控件使用存储过程来分页实现代码
- DataRelation 实现父子表 父子级 Repeater的嵌套使用
- Datalist控件使用存储过程来分页实现代码
- ASP.NET SignaiR 实现消息的即时推送,并使用Push.js实现通知的示例代码
- 使用 ServiceStack.Text 序列化 json的实现代码
- 【代码实现】使用PHP导入和导出CSV文件
- iOS开发笔记--使用Auto Layout中的VFL(Visual format language)--代码实现自动布局
- 使用CSS代码的空格实现中文对齐的方法
- flex中使用swc实现更好的界面代码分离
- 使用Auto Layout中的VFL(Visual format language)--代码实现自动布局