代码实例2:asp.net绑定数据到web控件之主/从表单
时间:2005-05-12 来源:bandt
摘自《ASP.NET揭秘》第十一章,英文名《ASP.NET UNLEASHED》
<%@ Import Namespace="System.Data.SqlClient" %>
<html>
<head><title>test.aspx</title></head>
<body>
<form Runat="Server">
<table width="100%">
<tr><td valign="top">
<asp:DataList
ID="dlstCategories"
OnItemCommand="dlstCategories_ItemCommand"
DataKeyField="CategoryID"
ItemStyle-BorderStyle="Solid"
ItemStyle-BorderColor="Blue"
Width="200"
CellPadding="5"
CellSpacing="10"
BackColor="lightgrey"
Runat="Server">
<ItemTemplate>
<asp:LinkButton
Text='<%# Container.DataItem( "CategoryName" )%>'
Runat="Server" />
</ItemTemplate>
<SelectedItemTemplate>
<b><i><%# Container.DataItem( "CategoryName" )%></i></b>
</SelectedItemTemplate>
</asp:DataList>
</td><td valign="top" width="100%">
<asp:Repeater
ID="rptProducts"
Runat="Server">
<ItemTemplate>
<%# Container.DataItem( "ProductName" ) %>
</ItemTemplate>
<SeparatorTemplate>
<hr>
</SeparatorTemplate>
</asp:Repeater>
</td></tr>
</table>
</form>
</body>
</html>