一,html代码
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>
<!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></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:DataList ID="DataList1" runat="server" RepeatDirection="Horizontal" RepeatColumns="2">
<ItemTemplate>
<table width="129" border="0" cellpadding="0" cellspacing="0" class="TB-TWORE">
<tr bgcolor="#2d6b86">
<td height="29" align="center" valign="middle">
<a href="#" class="linkWhite14"><%# Eval("Name") %></a>
</td>
</tr>
<tr bgcolor="#2d6b86">
<td height="29" align="center" valign="middle">
<a href="#" class="linkWhite14"><%# Eval("Sex") %></a>
</td>
</tr>
<tr bgcolor="#2d6b86">
<td height="29" align="center" valign="middle">
<a href="#" class="linkWhite14"><%# Eval("Age") %></a>
</td>
</tr>
<tr bgcolor="#2d6b86">
<td height="29" align="center" valign="middle">
<a href="#" class="linkWhite14"><%# Eval("Money") %></a>
</td>
</tr>
</table>
</ItemTemplate>
<AlternatingItemTemplate>
<table width="129" border="0" cellpadding="0" cellspacing="0" class="TB-TWORE">
<tr bgcolor="#08466d">
<td height="29" align="center" valign="middle">
<a href="#" class="linkWhite14"><%# Eval("Name") %></a>
</td>
</tr>
<tr bgcolor="#08466d">
<td height="29" align="center" valign="middle">
<a href="#" class="linkWhite14"><%# Eval("Sex") %></a>
</td>
</tr>
<tr bgcolor="#08466d">
<td height="29" align="center" valign="middle">
<a href="#" class="linkWhite14"><%# Eval("Age") %></a>
</td>
</tr>
<tr bgcolor="#08466d">
<td height="29" align="center" valign="middle">
<a href="#" class="linkWhite14"><%# Eval("Money") %></a>
</td>
</tr>
</table>
</AlternatingItemTemplate>
</asp:DataList>
</div>
</form>
</body>
</html>
二,cs文件代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class Default2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BindData();
}
}
private void BindData()
{
List<People> list = new List<People>();
list.Add(new People("李华", 35, "女", 266));
list.Add(new People("李金", 20, "女", 1000000));
list.Add(new People("李明", 10, "女", 2000));
list.Add(new People("李月", 11, "女", 1000));
list.Add(new People("李静", 23, "女", 100110000));
list.Add(new People("李天", 11, "男", 2));
list.Add(new People("李东", 11, "男", 10200000));
list.Add(new People("李秋", 33, "男", 2));
this.DataList1.DataSource = list;
this.DataList1.DataBind();
}
public class People
{
private string name;
private int age;
private string sex;
private int money;
public People(string name, int age, string sex, int money)
{
this.name = name;
this.sex = sex;
this.age = age;
this.money = money;
}
public string Name
{
get {
return this.name;
}
}
public int Age
{
get
{
return this.age;
}
}
public string Sex
{
get
{
return this.sex;
}
}
public int Money
{
get
{
return this.money;
}
}
}
}
三,最张效果