SQLDataSource + DataList + ItemTemplate 使用方法
Default.aspx |
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="Data Source=.\SqlExpress; Initial Catalog=Soccer; Integrated Security=SSPI" SelectCommand="SELECT * FROM dbo.Result_View;" /> <asp:DataList ID="DataList1" runat="server" DataSourceID="SqlDataSource1"> <ItemStyle ForeColor="#444444" /> <AlternatingItemStyle BackColor="#666666" ForeColor="White" /> <HeaderStyle BackColor="#444444" ForeColor="White" Font-Bold="true" /> <HeaderTemplate> <table border="0" cellpadding="0" cellspacing="0"> <tr> <td width="175"><strong>Player</strong></td> <td width="175"><strong>Team</strong></td> <td width="300"><strong>League</strong></td> </tr> </table> </HeaderTemplate> <ItemTemplate> <table border="0" cellpadding="0" cellspacing="0"> <tr> <td width="175"><%# Eval("Player") %></td> <td width="175"><%# Eval("Team") %></td> <td width="300"><%# Eval("League")%></td> </tr> </table> </ItemTemplate> </asp:DataList> |